开发者

How to control the size of the select box in Ruby on Rails 3?

开发者 https://www.devze.com 2023-01-30 00:55 出处:网络
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 ?

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)
开发者_如何学Python

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

0

精彩评论

暂无评论...
验证码 换一张
取 消