Rails select_tag css with options_from_collection_for_select

时间:2017-12-29 18:43:57

标签: css ruby-on-rails forms

我在Rails中有一个form_tag,如下所示:

    <%= form_tag(listings_path, method: :get) do %>
      What 
      <%= text_field_tag :title, "",class: 'form-control' %>

      Category
      <%= select_tag(:category_id, options_from_collection_for_select(Category.all, :id, :name), { :prompt => 'All Categories' }) %>

      Area 
      <%= select_tag(:area, options_for_select(['All', 'Ireland', 'UK']), class: "form-control") %>

      <%= submit_tag 'Search', name: nil, class: "btn btn-primary" %>
    <% end %>

我应该在哪里添加CSS选项&gt;&gt; class:&#34; form-control&#34; &LT;&LT;为区域字段让它工作?我尝试了几个我在SO上找到但没有运气的选项

3 个答案:

答案 0 :(得分:1)

我在我的应用程序中将它设置为与您略有不同,但这样做有效。

...

<% options = options_from_collection_for_select(Category.all, :id, :name) %>
<%= f.select :category_id,  options, class: "form-control", :include_blank => 'All Categories' %>

...

答案 1 :(得分:0)

<%= select_tag "area", options_for_select(['All', 'Ireland', 'UK']), :include_blank => '--Choose an option--', class: 'form-control' %>

答案 2 :(得分:-1)

转到应用&gt;&gt;资产&gt;&gt;样式表并在任何scss页面发布