undefined方法merge_wrapper_options

我正在尝试使用Simple表单的假输入,如下所示: https : //github.com/plataformatec/simple_form/wiki/Create-a-fake-input-that-does-NOT-read-attributes 。

f.input :address, as: :fake 

但是,我得到一个错误“未定义的方法`merge_wrapper_options’为#”。 即使重新启动rails服务器,我也会收到此错误。

请帮我解决这个问题。

谢谢。

摘要

实例方法merge_wrapper_optionsSimpleForm::Inputs::Base类上定义,但直到版本3.1.0.rc1。

这是版本3.0.2的相关源代码(没有merge_wrapper_options ):

https://github.com/plataformatec/simple_form/blob/v3.0.2/lib/simple_form/inputs/base.rb

与3.1.0.rc1版本对比:

https://github.com/plataformatec/simple_form/blob/v3.1.0.rc1/lib/simple_form/inputs/base.rb

因此,如果你是v3.0.2或之前,你将无法拥有它。 但是,没什么大不了的,只需自己定义方法:

/app/inputs/fake_string_input.rb

 class FakeStringInput < SimpleForm::Inputs::StringInput # Creates a basic input without reading any value from object def input(wrapper_options = nil) merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) template.text_field_tag(attribute_name, nil, merged_input_options) end # method def merge_wrapper_options(options, wrapper_options) if wrapper_options options.merge(wrapper_options) do |_, oldval, newval| if Array === oldval oldval + Array(newval) end end else options end end # method end # class 

/app/views/some_form.html.haml

 = f.input :some_parameter, label: false, as: :fake_string, input_html: { value: 'some-value' } 

POST请求将包含:

 Parameters: {"utf8"=>"✓", "some_parameter"=>"some-value" }