Module: Pickel::ViewHelper

Defined in:
lib/pickel/view_helper.rb

Instance Method Summary collapse

Instance Method Details

#form_for(record, options = {}, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/pickel/view_helper.rb', line 26

def form_for(record, options = {}, &block)
  return super unless record.is_a?(Search)

  opts = options.dup
  opts[:scope] = opts.delete(:as)
  opts[:local] = !(opts.delete(:remote) == true)

  form_with(model: record, **opts, &block)
end

#form_with(model: nil, scope: nil, url: nil, format: nil, **options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pickel/view_helper.rb', line 13

def form_with(model: nil, scope: nil, url: nil, format: nil, **options)
  return super unless model.is_a?(Search)

  url ||= polymorphic_path(model.klass, format: format)
  scope ||= :q
  options[:builder] ||= FormBuilder
  options[:id] ||= model.html_id
  options[:class] ||= model.html_id
  options[:method] ||= :get

  super(model: model, scope: scope, url: url, **options)
end