我正在尝试选择一个SuperCategory,然后过滤MainCategories的下拉菜单。我收到以下错误
未定义方法`map':main_categories:符号
代码
<%= select_tag 'main_category_id', grouped_collection_select(:main_category_id, SuperCategory.active.order(:title), :main_categories, :title, :id, :title, include_blank: false) %>
答案 0 :(得分:1)
我认为你必须改变第二和第三个参数。 因为: 2 parameter - method - 与select标签对应的对象的属性 3 parameter - collection - 表示标记的对象数组。
在你的代码中,第三个参数是Symbol,它没有方法“map”。
http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/grouped_collection_select
答案 1 :(得分:0)
这最终为
工作<%= grouped_collection_select('grouped', :main_category_ids, SuperCategory.exclude_most_popular, 'sort_main_categories', :title, :id, :title, { :selected => selected_main, include_blank: false } ) %>