简单表单 - 无法识别自定义输入
Simple Form - Custom Input Not Being Recognized
所以我想为一个简单的表单定义一个自定义输入组件并具有以下内容:
# app/inputs/gds_input.rb
class GdsInput < SimpleForm::Inputs::Base
def input(wrapper_options = nil)
binding.pry
end
end
然后在表格中我有以下内容:
<%= builder.simple_fields_for :registration, registration do |reg| %>
<fieldset>
<%= reg.input :first_name, required: true, input_html: { maxlength: 40, class: 'gds-Input' }, as: :gds_input %>
</fieldset>
<% end %>
但是我在运行时遇到 No input found for gds_input
错误。
关于我没有考虑到的事情有什么想法吗?
您的自定义 class 必须有后缀 Input
,要使用它,您必须从 class 名称的 underscore
版本中删除该后缀。
你的情况:
# class name is GdsInput
reg.input :first_name, {...}, as: :gds
所以我想为一个简单的表单定义一个自定义输入组件并具有以下内容:
# app/inputs/gds_input.rb
class GdsInput < SimpleForm::Inputs::Base
def input(wrapper_options = nil)
binding.pry
end
end
然后在表格中我有以下内容:
<%= builder.simple_fields_for :registration, registration do |reg| %>
<fieldset>
<%= reg.input :first_name, required: true, input_html: { maxlength: 40, class: 'gds-Input' }, as: :gds_input %>
</fieldset>
<% end %>
但是我在运行时遇到 No input found for gds_input
错误。
关于我没有考虑到的事情有什么想法吗?
您的自定义 class 必须有后缀 Input
,要使用它,您必须从 class 名称的 underscore
版本中删除该后缀。
你的情况:
# class name is GdsInput
reg.input :first_name, {...}, as: :gds