Rails 3.1,从控制器传递 colection_select 参数
我认为有这个 collection_select 用法:
<%= collection_select(:production_year, :id, @car_models, :id, :name, { :prompt => "Year" }, { :disabled => "disabled" } ) %>
但看来,我会为此选择框添加很多逻辑。所以我想从我的控制器传递这个 collection_select 的参数。我该怎么做?
试图传递带有参数的数组,但出现了很多错误。请显示正确的方法。
I have this collection_select usage in my view:
<%= collection_select(:production_year, :id, @car_models, :id, :name, { :prompt => "Year" }, { :disabled => "disabled" } ) %>
But it seems, that i'll add much logic for this select box. So i want pass parameters for this collection_select from my controller. How can i do this?
Was trying to pass array with parameters, but got many errors. Pls show correct way for this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的控制器中:
@collection_select_params = [ ... ]
在您的视图中:
<%= collection_select(*@collection_select_params) %>
*< /code> 前缀将向 ruby 指示该数组将作为参数列表传递。
In your controller:
@collection_select_params = [ ... ]
And in your view:
<%= collection_select(*@collection_select_params) %>
The
*
prefix will indicate to ruby that this array is to be passed as an args list.