3

This is my sign up form:

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>

  <p><%= f.label :email %><br />
  <%= f.email_field :email %></p>

  <p><%= f.label :password %><br />
  <%= f.password_field :password %></p>

  <p><%= f.label :password_confirmation %><br />
  <%= f.password_field :password_confirmation %></p>

  <%= f.fields_for :profile do |t| %>
     <div class ="field">
        <%= t.label :type, "Are you an artist or listener?" %><br />
        <p> Artist: <%= t.radio_button :type, "Profile::Artist", :id => "artist_button" %></p>
        <p> Listener: <%= t.radio_button :type, "Profile::Listener", :id => "listener_button" %></p>
      </div>
  <% end %>

  <p><%= f.submit "Sign up", :id => "new_user_submit" %></p>
<% end %>

I also have this in my user model:

 accepts_nested_attributes_for :profile

However the problem is that the radio buttons that is nested in the form is not even appearing on the page. How can I fix this?

1 Answer 1

4

You probably need to build an empty profile object on your User object (or whatever it's called) first:

@user.build_profile
Sign up to request clarification or add additional context in comments.

2 Comments

Where did you add this line ?
for future visitors: you write this in the #new method of the controller serving this form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.