Rails应用程序中的嵌套表单错误

与此问题相关的模型:用户,朋友,兴趣,person_interest。 Person_interest是多态的,可以存储属于用户或朋友的兴趣。

兴趣预先填充大约。 30个利益。 当用户注册时,他们被要求选择自己的兴趣,然后在表单中输入他们的朋友姓名,选择该人的兴趣。

尝试使用 :check_boxes, :label => false %>来实现此目的

但得到以下错误:

 NoMethodError in User_steps#show Showing /Users/nelsonkeating/Desktop/ReminDeal/app/views/user_steps/show.html.erb where line #30 raised: undefined method `to_i' for []:ActiveRecord::Relation Extracted source (around line #30): 27: :end_year => Date.today.year - 12, 28: :order => [:month, :day, :year ] %> 29:  ['male','female'] %> 30:  :check_boxes, :label => false %> 31:  32: 33: Rails.root: /Users/nelsonkeating/Desktop/ReminDeal Application Trace | Framework Trace | Full Trace app/views/user_steps/show.html.erb:30:in `block (2 levels) in _app_views_user_steps_show_html_erb__1202886937753978667_70281885932700' app/views/user_steps/show.html.erb:23:in `block in _app_views_user_steps_show_html_erb__1202886937753978667_70281885932700' app/views/user_steps/show.html.erb:1:in `_app_views_user_steps_show_html_erb__1202886937753978667_70281885932700' Request Parameters: {"id"=>"show"} 

这是表格..

     true %>   :date, :start_year => 1900, :end_year => Date.today.year - 12, :order => [ :day, :month, :year] %>  [:male, :female] %> 

Select your top 3 interests..

:check_boxes, :label => false %>

What holidays do you celebrate?

:check_boxes, :label => false %>

Add up to 10 friends birthdays that you would like to remember..

:Birthday, :as => :date, :start_year => Date.today.year - 90, :end_year => Date.today.year - 12, :order => [:month, :day, :year ] %> ['male','female'] %> :check_boxes, :label => false %> 'btn btn-success' %>

Git repo在这里: https : //github.com/nelsonkeating/ReminDeal

你有什么理由要避免friend_f.association吗?

 <%= friend_f.association :interests, :as => :check_boxes, :label => false %> 

适合我。 或者改变:interests :interest_ids kasper代码中的interest_ids,也应该有效。

 <%= friend_f.input :interest_ids, :as => :check_boxes, :label => false, :collection => Interest.all %> 

尝试编写代码<%= friend_f.input :interests, :as => :check_boxes, :label => false %> with :collection key。 例如:

 <%= friend_f.input :interests, :as => :check_boxes, :label => false, :collection => Interest.all %>