将样式类添加到select_country字段

DDD*_*DDD 2 ruby-on-rails twitter-bootstrap ruby-on-rails-4

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"} %>
Run Code Online (Sandbox Code Playgroud)

这显示了一个丑陋的默认选择类,它还添加了"class"和"id"作为选择选项,因此语法明显偏离.有任何想法吗?

Kir*_*rat 7

class并且idhtml选项,它们应该作为country_select方法的第三个参数传递.第二个参数是要在下拉列表中显示的选项列表,这就是您在下拉列表中看到idclass作为可选选项而不是作为html选项应用的原因.

您可以执行以下操作:

<%= f.country_select :ship_country, {}, {class: "dropdown", :id => "payment_ship_country"} %>
Run Code Online (Sandbox Code Playgroud)

供您参考,请参阅以下country_select文档中的示例:

Supplying additional html options:

country_select("user", "country", { priority_countries: ["GB", "FR"] }, { selected: "GB", class: 'form-control' })
Run Code Online (Sandbox Code Playgroud)

这应该在这里工作:

<%= f.country_select :ship_country, priority_countries = ["United States"], options = {}, html_options = {:class => "input-lg", :id => "payment_country"} %>
Run Code Online (Sandbox Code Playgroud)