2014-04-21 53 views
0

我正在使用ruby on rails應用程序並嘗試減小select的大小。我爲我的應用程序安裝了「bootstrap gem」。 下面是代碼bootstrap類不與選擇

<%= f.select :fromyear, (1995..Time.now.year).to_a.reverse, 
    :include_blank => {:year => "Select year"}, :class=>"input-small" %> 

,因爲我注意到從這個問題Change width of select tag in Twitter Bootstrap類值。但似乎它不適用於此選擇。我已經嘗試過

<%= f.select :fromyear, (1995..Time.now.year).to_a.reverse, 
    :include_blank => {:year => "Select year"}, :style=>"100px" %> 

但是什麼也沒有發生。 Plz讓我知道我失蹤了。謝謝

+0

請告訴你使用'simple_form '或內置'form_for'? –

+0

@Monk_Code我正在使用'form_for' –

+0

我在其他頁面上使用form_for。它在這個觀點上工作得很好 –

回答

0

試試這個

<%= f.select(:fromyear, options_for_select((1995..Time.now.year).to_a.reverse), {:include_blank => 'Select year'}, { :class => 'input-small' }) %> 

或者你甚至可以包括選擇標籤中內嵌樣式與

<%= f.select(:fromyear, options_for_select((1995..Time.now.year).to_a.reverse), {:include_blank => 'Select year'}, { :class => 'input-small', :style => 'width:200px;', required: true }) %> 
1

也許你忘了輸入'寬度'的選項:風格?

:style=>"width:100px" 
1

您是否試過這種方式?

= a.input :country, :as => :select, :collection => country_code_localized_map, :include_blank => false, :input_html=>{:class => "reg-input"} 

要不然你可以添加其他%DIV.select_above_class選擇標籤上方,通過上面的類應用樣式,選擇標籤

.select_above_class select{ 
    // your css styles 
} 
2

按照語法爲f.select(在form_for):

f.select(method, choices = nil, options = {}, html_options = {}, &block)

現在你正在通過include_blankclass作爲options參數,這就是爲什麼class沒有應用。 class必須去html_options

所有你需要做的是分離出optionshtml_options

<%= f.select :fromyear, (1995..Time.now.year).to_a.reverse, 
    {:include_blank => {:year => "Select year"}}, :class=>"input-small" %> 
    ^          ^
    ## Added a curly bracket to separate out `include_blank` option and `class` option.