【问题标题】:How to add class attribute to select tag in rails 3如何在rails 3中添加类属性以选择标签
【发布时间】:2012-08-16 06:52:55
【问题描述】:

我想在 rails 3 中添加类属性来选择标签 我的代码是

<div >
    <%= f.label :type %><br />
    <%= f.select "type_id", options_from_collection_for_select(@type,
    "type_id","name"),:include_blank=>true%>

</div>

我的问题是我想为这个选择标签添加一个特定的类名以进行验证。 我尝试添加

  :class=>"myclassname"

但它对我不起作用。请解决我的问题

【问题讨论】:

标签: ruby-on-rails validation html-select


【解决方案1】:

您可以像这样添加类属性。检查select

<%= f.select "type_id", 
    options_from_collection_for_select(@type, "type_id","name"), 
    { :include_blank => true }, 
    { :class => 'myclassname' } %>

【讨论】:

  • 这对我来说很好用。我的问题是我没有在 :include_blank=>true 和 :class=>"myclass" 周围使用大括号{}...再次感谢 Kulbir
  • 我自己多次遇到这个问题。我总是忘记大括号:)
猜你喜欢
  • 1970-01-01
  • 2015-11-06
  • 2010-11-02
  • 2021-01-25
  • 1970-01-01
  • 1970-01-01
  • 2016-10-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多