Class: SimpleFormRansack::FormProxy
- Inherits:
-
Object
- Object
- SimpleFormRansack::FormProxy
- Defined in:
- lib/simple_form_ransack/form_proxy.rb
Instance Method Summary collapse
-
#initialize(args) ⇒ FormProxy
constructor
A new instance of FormProxy.
- #input(name, *args) ⇒ Object
- #method_missing(method_name, *args, &blk) ⇒ Object
Constructor Details
#initialize(args) ⇒ FormProxy
Returns a new instance of FormProxy.
2 3 4 5 6 7 8 9 10 |
# File 'lib/simple_form_ransack/form_proxy.rb', line 2 def initialize(args) @resource = args[:resource] @object = @resource.object @class = @resource.klass @params = args[:params] @form = args[:form] raise "No params given in arguments: #{args.keys}" unless @params end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &blk) ⇒ Object
32 33 34 |
# File 'lib/simple_form_ransack/form_proxy.rb', line 32 def method_missing(method_name, *args, &blk) @form.__send__(method_name, *args, &blk) end |
Instance Method Details
#input(name, *args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/simple_form_ransack/form_proxy.rb', line 12 def input(name, *args) if args.last.is_a?(Hash) opts = args.pop else opts = {} end attribute_name = real_name(name, opts) as = as_from_opts(attribute_name, opts) input_html = opts.delete(:input_html) || {} set_value(as, name, opts, input_html) set_name(as, name, input_html) set_label(attribute_name, opts, input_html) opts[:required] = false unless opts.key?(:required) opts[:input_html] = input_html args << opts return @form.input(attribute_name, *args) end |