Having difficulty adding a class tag to this:
<div class="field">
<%= label_tag(:school_or_org, "Are you a school or a non-profit organization?") %>
<%= select_tag(:school_or_org, options_for_select([ ['school', "school"], ['non-profit', "non-profit"] ])) %>
</div>
This is what I've tried, among others:
<div class="field">
<%= label_tag(:school_or_org, "Are you a school or a non-profit organization?") %>
<%= select_tag(:school_or_org, options_for_select([ ['school', "school"], ['non-profit', "non-profit"], {:class => 'form-control'} ])) %>
</div>
When I check it via firefbug, I don' see the class information, so clearly it's not being added.
How do I get it added so it shows up in the form?
Merci
Edit One
Do you mean like this:
<%= select_tag(:school_or_org, options_for_select([ ['school', "school"], ['non-profit', "non-profit"]] ), {:class => 'form-control'}) %>
It didn't work.
Just for reference, this is what I'm trying to have the select box look like: http://getbootstrap.com/css/#forms (look at Selects section). That's where I got 'form-control' from.
If you are using the select
helper, you need an empty options hash followed by your html options like so:
select(object, method, choices, options = {}, html_options = {})
With your example, that would look like this:
<%= select(:school_or_org, options_for_select([ ['school', "school"], ['non-profit', "non-profit"]] ), {}, {:class => 'form-control'}) %>
If you are using the select_tag
helper, you can add in the hash at the end as part of the options hash:
select_tag(name, option_tags = nil, options = {})
This works because any options that are not recognised are passed in as standard HTML attributes.
With your example , that would look like this:
<%= select_tag(:school_or_org, options_for_select([ ['school', "school"], ['non-profit', "non-profit"]] ), {:class => 'form-control'}) %>
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