因此,我希望为一个简单的表单定义一个自定义输入组件,并具有以下内容:
# 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
错误。关于那些我没有说明的事情有什么想法吗?
最佳答案
自定义类必须有一个后缀Input
,若要使用它,必须从该类名的underscore
版本中删除该后缀。
就你而言:
# class name is GdsInput
reg.input :first_name, {...}, as: :gds
关于ruby-on-rails - 简单表格-无法识别自定义输入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46694416/