Class: Paltrow::Navigating::Rails::Redirect

Inherits:
Object
  • Object
show all
Defined in:
lib/paltrow/navigating/rails/redirect.rb

Instance Method Summary collapse

Instance Method Details

#adapt_params_to_railsObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/paltrow/navigating/rails/redirect.rb', line 15

def adapt_params_to_rails
  lambda do |params|
    if params.is_a?(Hash)
      params
        .merge(_recall: {})
        .transform_keys { |key| key.to_s.gsub("resource", "controller").to_sym }
    else
      params
    end
  end
end

#call(handler:, page:) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/paltrow/navigating/rails/redirect.rb', line 5

def call handler:, page:
  handler.flash[:notice] = page.notice unless page.notice.empty?
  handler.flash[:alert] = page.alert unless page.alert.empty?

  page
    .to_params
    .then(&adapt_params_to_rails)
    .then { |params| handler.redirect_to(params) }
end