![](/img/trans.png)
[英]How to add a class on an option tag that belongs to a select tag in rails?
[英]How to add class attribute to select tag in rails 3
我想在我的代码中使用rails 3中的class属性添加class属性
<div >
<%= f.label :type %><br />
<%= f.select "type_id", options_from_collection_for_select(@type,
"type_id","name"),:include_blank=>true%>
</div>
我的问题是我想为这个select标签添加一个特定的类名以进行验证。 我尝试添加
:class=>"myclassname"
但它对我不起作用。解压我的问题
您可以像这样添加类属性。 选中
<%= f.select "type_id",
options_from_collection_for_select(@type, "type_id","name"),
{ :include_blank => true },
{ :class => 'myclassname' } %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.