CSS类选择器不能用于form.collection_select Rails 5

问题描述 投票:0回答:1

我正在尝试将一些样式应用于Rails 5中的form.collection_select助手类。但遗憾的是它没有得到应用。

你能告诉我我做错了什么吗?

1)

<%= form.collection_select(:manager_id, User.all, :id, :full_name, :include_blank => "Select None", :class => "input-with-icon") %>

2)

<%= form.collection_select(:manager_id, User.all, :id, :full_name, :include_blank => "Select None", {:class => "input-with-icon" }) %>

退货:

<select name="user[manager_id]" id="user_manager_id">
<option value="">Select None</option>
<option value="15601867">xxxxxxxxxxxxxxxxxx</option>

ruby-on-rails ruby html5 css3
1个回答
1
投票

collection_select就是这样构建的(source):

collection_select(object,method,collection,value_method,text_method,options = {},html_options = {})

因此,您需要为选项选项传递哈希值,并为html选项传递其他哈希值:

<%= form.collection_select(:manager_id, User.all, :id, :full_name, { include_blank: "Select None" }, { class: "input-with-icon" }) %>
© www.soinside.com 2019 - 2024. All rights reserved.