Ruby on Rails 4。
我安装了gem 'country_select', '~> 1.3.1'
并让下拉工作有点奇怪。我找不到有关在该字段中添加样式类的文档。
我需要在JS中使用的id,我试图在字段中使用Bootstrap类。任何下拉课程都会很好:
<%= f.label :ship_country, "Country:" %><br>
<%= f.country_select :ship_country, {class: "dropdown", :id => "payment_ship_country"} %>
这显示了一个丑陋的默认选择类,它还添加了“class”和“id”作为选择选项,因此语法明显偏离。有什么想法吗?
答案 0 :(得分:6)
class
和id
是html
选项,它们应作为第三个参数传递给country_select
方法。第二个参数用于显示在下拉列表中的选项列表,这就是您在下拉列表中看到id
和class
作为可选选项而不是应用为html选项的原因。
您可以执行以下操作:
<%= f.country_select :ship_country, {}, {class: "dropdown", :id => "payment_ship_country"} %>
供您参考,请查看以下country_select
文档中的示例:
Supplying additional html options:
country_select("user", "country", { priority_countries: ["GB", "FR"] }, { selected: "GB", class: 'form-control' })
这应该来自here:
<%= f.country_select :ship_country, priority_countries = ["United States"], options = {}, html_options = {:class => "input-lg", :id => "payment_country"} %>