簡體   English   中英

如何在Rails上的ruby中為select添加一個類?

[英]How do I add a class to a select in ruby on rails?

這就是我一直在嘗試的:

<%= select (:filter, :min_sale_price, item.buy_prices.map {|p| [Money.new(p, :gbp).format(:no_cents), p / 100]}, selected: params[:filter] && params[:filter][:min_sale_price], include_blank: 'No minimum', :class => "form-control") %><br />

我也嘗試過使用:

, class: "form-control")

您需要對HTML選項中的Rails選項進行分組

<%= select (:filter, :min_sale_price, item.buy_prices.map {|p| [Money.new(p, :gbp).format(:no_cents), p / 100]}, {selected: params[:filter] && params[:filter][:min_sale_price], include_blank: 'No minimum'}, {:class => "form-control"}) %><br />

您正在調用的方法的簽名如下:

select(object, method, choices = nil, options = {}, html_options = {}, &block)

在不包裝各種選項的散列的任何部分的情況下,它們將全部假定為單個散列,並將作為options傳遞給該方法的第4個參數。

為避免這種情況,應將大括號內的第一組(或兩組)選項分組,以將預期的哈希顯式傳遞給方法的正確參數:

<%= select(:filter, :min_sale_price, item.buy_prices.map {|p| [Money.new(p, :gbp).format(:no_cents), p / 100]}, {selected: params[:filter] && params[:filter][:min_sale_price], include_blank: 'No minimum'}, :class => "form-control") %><br />

更新:

我注意到您在致電select之后,括號前有一個空格。 您需要刪除括號(保留空格)或刪除空格。 您不能有空格和括號。

暫無
暫無

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

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