Nested form with design

This is my registration 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 switches embedded in the form do not even appear on the page. How can i fix this?

+3
source share
1 answer

Probably you first need to create an empty profile object on your User object (or something else):

@user.build_profile
+4
source

All Articles