I'm using the simple_form gem.
I'm rendering an input based on a collection (a list of all my actiontypes
)
<%= f.association :actiontype, collection: Actiontype.all, input_html: { data: {'impacts-pnl' => ??}} %>
I would like to be able to add a data-attribute to the input to store extra data.
In this case, I want to store the impacts_pnl
attribute of my actiontype
. The only problem is that I don't know how to refer to the current actiontype
collection.impacts_pnl
doesn't work (obviously)
actiontype.impacts_pnl
neither.
how can I pass this extra bit of data to my input?
If you want to add these attributes to the option-elements of a selectfield, you should alter the collection by using for example the .map() function. Also, use the input helper with block to do this, otherwise it doesn't work;
= f.input :actiontype do
= f.select :actiontype, Actiontype.all.map{|a| [a.name, a.id, {"data-impacts-pnl" => p.impacts_pnl}]}
For more information about this issue, see https://github.com/plataformatec/simple_form/issues/188
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