Module: ParamsKeeper::Helper

Defined in:
lib/params_keeper/helper.rb

Instance Method Summary collapse

Instance Method Details

#form_with(**options, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/params_keeper/helper.rb', line 11

def form_with(**options, &block)
  return super unless controller
  return super if options[:method].to_s.downcase != 'get'

  html = super
  url_options = options[:url] || options[:model]
  hidden_fields = ParamsKeeper::HiddenFields.new(controller, url_options).call
  if hidden_fields.present?
    html.sub(/^(<form[^>]*>)/) { "#{$1}#{hidden_fields}" }.html_safe
  else
    html
  end
end

#url_for(url_options = nil) ⇒ Object



5
6
7
8
9
# File 'lib/params_keeper/helper.rb', line 5

def url_for(url_options = nil)
  return super unless controller

  ParamsKeeper::UrlFor.new(self, controller, url_options).call || super
end