<%= collection_select(:catgory, :id, @categories, :id, :title, {}, data: { behavior: 'category_dropdown' }) %>
In the above code I need to pass a parameter to the title method. Is there any way to do this with collection_select?
<%= collection_select(:catgory, :id, @categories, :id, (:title, @program), {}, data: { behavior: 'category_dropdown' }) %>
Edit: Looking at the internals for collection_select the text_method. It is eventually passed to a .send method which should allow for element.send(:title, @program). However, I think the issue why I still can't pass the param is that collection select is reading (:title, @program) as two params instead of one.
Use select instead:
select "catgory", "id", @categories.map{|c| [c.title(@program), c.id]}, {}, data: { behavior: 'category_dropdown' }
Should be working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With