<%= collection_select(:catgory, :id, @categories, :id, :title, {}, data: { behavior: 'category_dropdown' }) %>
在上面的代码中,我需要将参数传递给title方法。有没有办法用collection_select来做到这一点?将参数传递给text_method的集合选择方法
<%= collection_select(:catgory, :id, @categories, :id, (:title, @program), {}, data: { behavior: 'category_dropdown' }) %>
编辑: 纵观内部的collection_select的text_method。它最终传递给.send方法,该方法应该允许element.send(:title,@program)。但是,我认为为什么仍然无法传递参数的问题是,collection select正在读取(:title,@program)作为两个参数而不是一个参数。
你有访问在您的类别模型中使用@program? – InternetSeriousBusiness 2012-08-02 16:41:19
不幸的是它是一个has_many关系,所以我需要通过程序来知道哪个程序要放在标题中。 – John 2012-08-02 16:42:45