我们正在从Rails 3.2.13迁移到Rails 4.0.13。grouped_collection_select - group_method从Rails 3更改为4
我们使用Rails帮手grouped_collection_select
来嵌套<optgroup>
s。
我注意到,从Rails 3.2.13到4.0.2有源变化。
http://apidock.com/rails/v4.0.2/ActionView/Helpers/FormOptionsHelper/grouped_collection_select
我们的方法的使用目前不工作。
这里我们的代码:
<%= f.grouped_collection_select :location_id, @participating_businesses, :"active_locations(#{current_user.id})", :name, :id, :name, {prompt: t('.prompt_select_location')}, class: 'location-selector form-control' %>
以下是错误:
ActionView::Template::Error (undefined method `active_locations(7)' for #<ParticipatingBusiness:0x005583478f1f90>):
现在很明显,他们已经改变了如何GET方法的发送。
我在猜测,目前他们正在抓取group_method
选项并将其直接放入send(:group_method)
,这解释了上述错误。
但是,我怎么能传递一个参数给我的group_method
依赖于会话(又名current_user)。
查看来源,我不认为这是完全可能的。
我应该寻找到重新写这与我们的目标努力,没有助手或一点点更多的手册?
有没有人遇到同样的问题?
鉴于你知道,它不过直接传递'group_method'变量送,如果你试图用'[:active_locations,current_user.id]'呢? –
这是一个非常聪明的解决方法,但是我已经尝试过并且得到了'ActionView :: Template :: Error([:active_locations,7]不是一个符号)''。 – fbelanger
darn:/如果刚刚工作好了,你可能需要为Rails提供功能请求。看起来像普通的'collection_for_select'可以采用'Proc',但是我看到了一个问题,那就是'分组'版本不能以同样的方式工作 –