undefined method merge_wrapper_options

折月煮酒 提交于 2019-12-02 03:16:27

Summary

The instance method merge_wrapper_options is defined on the SimpleForm::Inputs::Base class, but not until version 3.1.0.rc1.

Here's the relevant source code for version 3.0.2 (no merge_wrapper_options):

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

Contrast this with version 3.1.0.rc1:

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

So if you're at v3.0.2 or prior, you won't have it. But, no big deal, just define the method yourself:

Code

/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' }

The POST request will contain:

Parameters: {"utf8"=>"✓", "some_parameter"=>"some-value" }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!