Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass a parameter into collection select method for text_method

  <%= 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.

like image 893
John Avatar asked Mar 27 '26 02:03

John


1 Answers

Use select instead:

select "catgory", "id", @categories.map{|c| [c.title(@program), c.id]}, {}, data: { behavior: 'category_dropdown' }

Should be working.

like image 77
Anthony Alberto Avatar answered Mar 28 '26 17:03

Anthony Alberto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!