我想在select标签中的一个选项元素中添加一个类(“has-versions”),具体取决于选项。我该如何添加该类?
= select_tag 'project_version_id', "<option value='' disabled>-optional select version-</option>".html_safe + options_from_collection_for_select(current_user.current_project.project_versions, :id, :name, @test_case.script.try(:project_version_id))
我需要它是这样的:
<select name="project_version_id" id="project_version_id">
<option disabled="" value="">-optional select version-</option>
<option selected="selected" value="19">NOOB SAIBOT</option>
<option class="has-versions" value="20">PEW PEW</option>
</select>
答案 0 :(得分:6)
以下是让您入门的内容: 2项改进:
:include_blank
作为&#34;入门者&#34;值:class
。
<%= select
"new_something",
"project_version_id",
options_for_select(["Item11", ["Item 2",{:class=>'has-versions'}]]),
{:include_blank => '-optional select version-'} %>
提示:您可以在数组上使用collect
根据需要生成options_for_select
。