Ruby on rails rails simpleform关联中的占位符
如何在rails simpleform关联中放置占位符。我尝试过不同的方法,但都不管用。目标代码是:Ruby on rails rails simpleform关联中的占位符,ruby-on-rails,simple-form,Ruby On Rails,Simple Form,如何在rails simpleform关联中放置占位符。我尝试过不同的方法,但都不管用。目标代码是: <%= f.association :sex, :include_blank => true %> true%> 请检查初始化器中的simple_form.rb 你可以在下面找到一些东西 # Use this setup block to configure all options available in SimpleForm. SimpleForm.setup do
<%= f.association :sex, :include_blank => true %>
true%>
请检查初始化器中的simple_form.rb
你可以在下面找到一些东西
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
.
.
.
config.wrappers :default, :class => :input, :hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
## Extensions enabled by default
# Calculates placeholders automatically from I18n
# You can also pass a string as f.input :placeholder => "Placeholder"
b.use :placeholder
.
.
end
end
所以它取决于翻译文件
所以你需要为user
modelsex
属性做些什么
en:
simple_form:
placeholders:
user:
sex:
As占位符用于输入
那你试试这个
<% f.association :user do |u| %>
<%= u.input :sex %>
<% end %>
而且它应该有效true,占位符:“sex”%>
<%= f.association :sex, :include_blank => true, placeholder: "sex" %>
使用Rails 5.0.0.beta2和Simple Form 3.2.1,这对我来说很有用:
<%= f.association :strands,
collection: Strand.order(label: :asc),
include_blank: "-- Select strands --"
%>
我在
:prompt
和我在这里找到的其他一些建议中没有使用各种排列方式。如果您使用Select2,您可以。要求包括一个空白元素作为第一项,您可以将占位符文本作为数据HTML属性
就你而言:
<%= f.association :sex, include_blank: true,
data: { placeholder: 'Search...'} %>
当他们想说性别时,为什么称之为性
?;)它适用于输入字段,但对于关联仍然不起作用。
试试这个,输入html:{'data-placeholder'=>'sex'}%>placeholder不是select元素的属性,在Rails 5/Simple Form 3.2.1中也不起作用