2011-05-17 98 views
3

這是我的註冊表格:嵌套形式色器件

<%= 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 

然而,問題是,嵌套在單選按鈕表單甚至沒有出現在頁面上。我怎樣才能解決這個問題?

回答

4

您可能需要首先用戶對象(或任何它被稱爲)上建一個空的配置文件對象:

@user.build_profile 
+0

這很有趣,+1 :) – apneadiving 2011-05-17 22:02:57

+0

你在哪裏加入這一行? – Luc 2013-02-12 11:24:24