Module: FilterFu::ViewHelper::InstanceMethods

Defined in:
lib/filter_fu/view_helper.rb

Instance Method Summary collapse

Instance Method Details

#filter_form_for(*args, &block) ⇒ Object Also known as: filter_form

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/filter_fu/view_helper.rb', line 22

def filter_form_for(*args, &block)
  raise ArgumentError, 'Missing block' unless block_given?

  opts = args.extract_options!
  name = (args.first || :filter).to_sym

  opts[:ignore_parameters] ||= []
  opts[:ignore_parameters] += FilterFu.ignore_parameters + [:controller, :action, name]
  opts[:ignore_parameters].uniq!

  opts[:html] ||= {}
  opts[:html][:method] ||= :get
  opts[:as] = name
  opts[:url] = {}

  form_for(FilterFu::FilterModel.new(params[name]), opts) do |f|
    hidden_fields_for(params, opts)
    block.call(f)
  end
end