Reputation: 4038
I have a collection_select:
f.collection_select(:selected_id, @subcategories, :id, :cat_transl)
which turns into the following tags:
<option value="4">Deutsch</option>
<option value="5">Chinesisch</option>
<option value="6">Spanisch</option>
<option value="10">Mathematik</option>
What I want is to add a attribute to every option
<option value="4" parent="3">Deutsch</option>
<option value="5" parent="3">Chinesisch</option>
<option value="6" parent="3">Spanisch</option>
<option value="10" parent="9">Mathematik</option>
How is this possible?
Thanks Markus
Upvotes: 1
Views: 1328
Reputation: 12412
If your really need this attribute despite the fact it's invalid HTML, use a "content_tag" helper method. You can build any tag with it manually.
<%= content_tag(:tag_name, 'text value', { :value => 'form_value', :anyattr => 'my_val' }) %>
Upvotes: 2
Reputation: 115412
This is not possible using the built-in Rails helpers, probably because it's not valid HTML. You can see which attributes the option
element supports here:
http://www.w3schools.com/TAGS/tag_option.asp
Upvotes: 0