我正在研究rails应用程序上的ruby并尝试减少select的大小。我有' bootstrap gem'为我的应用程序安装。 这是代码
<%= 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 :(得分:2)
根据f.select
(form_for
)的语法:
f.select(method, choices = nil, options = {}, html_options = {}, &block)
现在您将include_blank
和class
作为options
参数传递,这就是class
未应用的原因。 class
必须进入html_options
。
您需要做的只是分开 options
和html_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.
答案 1 :(得分:1)
也许你忘记输入宽度&#39;在选项中:样式?
:style=>"width:100px"
答案 2 :(得分:1)
= a.input :country, :as => :select, :collection => country_code_localized_map, :include_blank => false, :input_html=>{:class => "reg-input"}
或者你可以在select标签上方添加另一个%DIV.select_above_class
并通过上面的类应用样式来选择标签
.select_above_class select{
// your css styles
}
答案 3 :(得分: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 }) %>