嵌套形式与设计 [英] Nested form with devise
本文介绍了嵌套形式与设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的注册表单:
<%= 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 %>
我的用户型号还有:
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?
推荐答案
你可能需要在你的User对象上建立一个空的配置文件对象首先:
You probably need to build an empty profile object on your User object (or whatever it's called) first:
@user.build_profile
这篇关于嵌套形式与设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文