简体   繁体   English

如何在rails 3中添加class属性来选择标签

[英]How to add class attribute to select tag in rails 3

I want to add class attribute to select tag in rails 3 my code is 我想在我的代码中使用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>

My problem is that I want to add one specific class name to this select tag for validation purpose. 我的问题是我想为这个select标签添加一个特定的类名以进行验证。 I tried adding 我尝试添加

  :class=>"myclassname"

but it not worked for me.plz resolve my issue 但它对我不起作用。解压我的问题

You can add class attribute like this. 您可以像这样添加类属性。 Check select 选中

<%= 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM