Module: Facepalm::Rails::Controller::Redirects

Defined in:
lib/facepalm/rails/controller/redirects.rb

Instance Method Summary collapse

Instance Method Details

#iframe_redirect_code(target_url, custom_code = nil) ⇒ Object

Generates HTML and JavaScript code to redirect user with top frame location overwrite

Parameters:

  • target_url

    An URL to redirect the user to

  • custom_code (defaults to: nil)

    A custom HTML code to insert into the result document. Can be used to add OpenGraph tags to redirect page code.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/facepalm/rails/controller/redirects.rb', line 31

def iframe_redirect_code(target_url, custom_code = nil)
  %{
    <html><head>
      <script type="text/javascript">
        window.top.location.href = #{ target_url.to_json };
      </script>
      <noscript>
        <meta http-equiv="refresh" content="0;url=#{ target_url }" />
        <meta http-equiv="window-target" content="_top" />
      </noscript>
      #{ custom_code }
    </head></html>
  }
end

#redirect_from_iframe(url_options) ⇒ Object

Redirects user to a definite URL with JavaScript code that overwrites top frame location. Use it to redirect user from within an iframe.



14
15
16
17
18
19
20
21
22
23
# File 'lib/facepalm/rails/controller/redirects.rb', line 14

def redirect_from_iframe(url_options)
  redirect_url = url_options.is_a?(String) ? url_options : url_for(url_options)

  logger.info "Redirecting from IFRAME to #{ redirect_url }"

  render(
    :text   => iframe_redirect_code(redirect_url),
    :layout => false
  )
end

#redirect_to(*args) ⇒ Object

Overrides ActionController::Base#redirect_to to pass signed_request in flash[]



6
7
8
9
10
# File 'lib/facepalm/rails/controller/redirects.rb', line 6

def redirect_to(*args)
  flash[:signed_request] = fb_signed_request

  super(*args)
end