我正在学习Ruby on Rails,但仍然不熟悉该语言的某些部分。使用grouped_collection_select我试图过滤特定品牌汽车的所有相关模型...
我不确定groups_collection_select是否具有正确的参数,以及它们是否按正确的顺序排列,因为我遇到此错误并且似乎无法解决它:"未定义的方法`map' for" 3 Series":String"。
此外,我正在使用此railscast,并已将Javascript添加到相关文件中。
应用\ views_multi_search.html.erb
<%= select_tag ('make_id'),
options_from_collection_for_select(@makes, :id, :makes_info, 0 ),
:prompt => "Select a Make" %>
<%#= select_tag ('model_id'),
options_from_collection_for_select(@models, :id, :model_info, 0 ),
:prompt => "Select a Model" %>
<%= select_tag ('model_id'), grouped_collection_select(:model,:model_id,Model.all,:model_info,:model,:id,:model),:prompt => "Select a Model" %>
在application.html.erb中调用partial:
`
<%= render( :partial => '/multi_search',
:locals => {
:makes => @makes = Make.all,:models => @models = Model.all,
:my_path => '/cars/multi_find' })%>'
品牌和汽车模型的型号代码:
make.rb
class Make < ActiveRecord::Base
has_many :cars
has_many :model
模型:RB
has_many :cars
belongs_to :make
has_many :cars
belongs_to :make
任何帮助将不胜感激!
谢谢
答案 0 :(得分:0)
您需要做的一件事就是在Make class write
中has_many :models
而不是
has_many :model