如何在Rails表单中添加数据属性select标签?
我找到了这个Bootstrap Select项目及其Rails的gem 。 我想在select标签中实现搜索。
我检查元素,这里是HTML源:
Hot Dog, Fries and a Soda Burger, Shake and a Smile Sugar, Spice and all things nice
如何在表单选择标记中添加data-live-search="true"
?
我的表格选择:
我尝试过的:
但它不起作用。
尝试:
{class: "form-control selectpicker", "data-live-search" => "true" }
<%= f.select :food_id, options_for_select(Food.all.map{|c| [c.name, c.id]}, f.object.food_id), {}, {class: "form-control selectpicker", data: {"live-search": true}} %>
<%= f.select(:plan_id, {},{}, {'v-model'=>"plan_id",'@change'=>"onChange", class: "form-control"}) do %> <% Plan.all.each do |plan| %> <%= content_tag(:option,"#{plan.name.upcase} #{plan.max_items} #{number_to_currency(plan.price)}", value:plan.id, :data => {items: plan.max_items, price: plan.price}) %> <% end%> <% end%>