Nested form with devise

余生长醉 提交于 2019-12-12 16:17:22

问题


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:


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

@user.build_profile


来源:https://stackoverflow.com/questions/6037203/nested-form-with-devise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!