簡體   English   中英

帶有options_from_collection_for_select的Rails select_tag CSS

[英]Rails select_tag css with options_from_collection_for_select

我在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選項>>類:“ form-control” <<,以使Area字段起作用? 我嘗試了一些在SO上找到的選項,但是沒有運氣

我將其設置為與您在我的應用程序中稍有不同,但這是可行的。

...

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

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

轉到App >> assets >> stylesheet並發布在任何scss頁面中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM