簡體   English   中英

使用bootstrap_form_for在Rails 5中添加類以選擇字段

[英]Add class to select field in Rails 5 with bootstrap_form_for

我使用Rails 5和bootstrap_form_for來構建表單。

我知道在SO中有一些類似的問題,但沒有一個幫助我解決我的問題......

我正在嘗試將自定義類添加到選擇字段。 但我有這樣的:

<%= f.collection_select :location_id, Location.all, :id, :name, :include_blank => ("Insere um endereço ou escolha um local da lista..."), hide_label: true, :class => 'location' %>

但是這個課程沒有應用。 我能做些什么?

<%= f.collection_select(:location_id, Location.all, :id, :name, {:include_blank => ("Insere um endereço ou escolha um local da lista..."), hide_label: true}, class: "class-name") %>

您需要為方法參數的options部分添加空哈希。 我擔心它不是很直觀,但是如果你看一下方法簽名 ,就可以看出它為什么需要它。

collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {}) 


<%= f.collection_select :location_id, 
  Location.all, 
  :id, 
  :name, 
  :include_blank => ("Insere um endereço ou escolha um local da lista..."), 
  hide_label: true, 
  {},
 :class => 'location' %>

暫無
暫無

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

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