Ruby on Rails 4。
我安装好gem 'country_select', '~> 1.3.1'
了,下拉菜单有些奇怪。我找不到有关将样式类添加到字段的文档。
我需要一个ID,因为它在JS中使用,并且我试图在该字段中使用Bootstrap类。任何下拉类都不错:
<%= f.label :ship_country, "Country:" %><br>
<%= f.country_select :ship_country, {class: "dropdown", :id => "payment_ship_country"} %>
这显示了一个默认的选择类很丑陋,它还添加了“类”和“ id”作为选择选项,因此语法显然不正确。有任何想法吗?
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' })
这应该从这里工作:
<%= f.country_select :ship_country, priority_countries = ["United States"], options = {}, html_options = {:class => "input-lg", :id => "payment_country"} %>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句