我的订单/新页面中有这样的表格。我用它来选择模型位置,然后根据上面选择框中选择的内容从该位置选择一个模型。
<%= f.label "SELECT MODEL LOCATION *" %>
<div class="list_number">1</div><%= f.collection_select :location_id, Location.all, :id, :formatted_display, prompt: true, :required => true, :class => 'chosen-select' %>
<%= f.label "SELECT YOUR MODEL *" %>
<div class="list_number">2</div>
<%= f.grouped_collection_select :performer_id, Location.order(:name).map{|group| Performer.find_by_location_id(group.id).map{|performer| {'data-markup'=>performer.white_label.markup}}}, :performers, :name, :id, :first_name, include_blank: true, :required => true, class: 'chosen-select' %>
在 grouped_collection_select 中,当我使用 map 设置数据属性时,出现以下错误:
undefined method `map' for #<Performer:0x00000006813958>
如何解决此错误并获取所需数据?
尝试以下代码后
<%= f.grouped_collection_select :performer_id, Location.order(:name).map{|group| Performer.where(location_id: group.id).map{|performer| {'data-markup'=>performer.white_label.markup}}}, :performers, :name, :id, :first_name, include_blank: true, :required => true, class: 'chosen-select' %>
我收到以下错误
undefined method `performers' for [{"data-markup"=>#<BigDecimal:67e80c8,'0.0',9(36)>}]:Array
当我尝试以下
<%= f.grouped_collection_select :performer_id, Location.order(:name), :performers, :name, :id, :first_name,Location.order(:name).map{|group| Performer.where(location_id: group.id).map{|performer| {'data-markup'=>performer.white_label.markup}}}, include_blank: true, :required => true, class: 'chosen-select' %>
我收到以下错误
undefined method `merge' for #<Array:0x000000069705a8>