I create the select box like this:
f.select(:my_select_name, options_for_select(...))
How could I control the size (width) of the select box ?
For input text field I do:
f.text_field(:field_name, :size => my_size)
but for "select" it doesn't work.
Please advise.
In gist, I use:
<%= f.select(:my_select_name, [1,2,3,4,5], {}, :style => "width:70px") %>
Or if I am using something like Twitter Bootstrap, I use a class:
<%= f.select(:my_select_name, [1,2,3,4,5], {}, :class => "col-md-1") %>
The basic synatx for select is
select(object, method, choices, options = {}, html_options = {})
Options are replace by the dropdown option values and you can replace the html_options for the width.
eg. <% select("company", "branch_id", Branch.all.collect {|b| [ b.name, b.id ] }, { :prompt => "Select" }, {:class => "companySelect" })
For select_tag you can use
select_tag(name, option_tags = nil, options = {})
Here the option is similar to html_options of select.
eg. <%= select_tag 'company_name', options_for_select(get_company_name), :class => "select1"%>
For more details please see select Tag and select
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