Class: ParamsKeeper::HiddenFields

Inherits:
Object
  • Object
show all
Defined in:
lib/params_keeper/hidden_fields.rb

Instance Method Summary collapse

Constructor Details

#initialize(controller, url_options) ⇒ HiddenFields

Returns a new instance of HiddenFields.



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

def initialize(controller, url_options)
  @controller = controller
  @url_options = url_options
end

Instance Method Details

#callObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/params_keeper/hidden_fields.rb', line 10

def call
  return if @controller.class.keep_params_configs.blank?

  params = ParamsKeeper::Resolver.new(@controller, @url_options).call
  return if params.blank?

  CGI.parse(params.to_query).flat_map do |key, values|
    values.map { |value| @controller.view_context.hidden_field_tag(key, value, id: nil) }
  end.join.html_safe
end