app/controllers/application_controller.rb
# Redirect to the URL stored by the most recent store_location call or to the passed default.
Redirect to the URL stored by the most recent store_location call or to the passed default.
Redirect to the URL stored by the most recent store_location call or to the passed default .
def redirect_back_or_default(default_uri_or_active_record_instance = nil)
    back_uri = return_to_url || default_uri_or_active_record_instance
    store_location(nil)
    redirect_to back_uri and return if back_uri.is_a?(ActiveRecord::Base)
    back_uri = URI.parse(back_uri) rescue nil
    if back_uri.is_a?(URI::Generic) && back_uri.scheme.nil?
      back_uri = URI.parse("#{request.protocol}#{request.host_with_port}#{back_uri.to_s}")
    end
    if ! back_uri.nil? && %w( http ).include?(back_uri.scheme) &&
      (! logged_in? || [logout_url, login_url, new_user_url].select{|url| back_uri.to_s.include?(url)}.blank?)
      back_uri.query = nil if back_uri.query =~ /oauth_provider/i
      back_uri = back_uri.to_s
      back_uri = CGI.unescape(back_uri)
    else
      back_uri = root_url(protocol: 'http')
    end
    redirect_to back_uri
  end
def redirect_back_or_default ( default_uri_or_active_record_instance = nil ) back_uri = return_to_url || default_uri_or_active_record_instance store_location ( nil ) redirect_to back_uri and return if back_uri . is_a? ( ActiveRecord :: Base ) back_uri = URI . parse ( back_uri ) rescue nil if back_uri . is_a? ( URI :: Generic ) && back_uri . scheme . nil? back_uri = URI . parse ( "#{request.protocol}#{request.host_with_port}#{back_uri.to_s}" ) end if ! back_uri . nil? && %w( http ) . include? ( back_uri . scheme ) && ( ! logged_in? || [ logout_url , login_url , new_user_url ] . select { | url | back_uri . to_s . include? ( url ) } . blank? ) back_uri . query = nil if back_uri . query =~ / oauth_provider /i back_uri = back_uri . to_s back_uri = CGI . unescape ( back_uri ) else back_uri = root_url ( protocol : 'http' ) end redirect_to back_uri end
Redirect to the URL stored by the most recent store_location call or to the passed default.
Redirect to the URL stored by the most recent store_location call or to the passed default .
# If we've passed in an instance of active record, e.g. @user, we can redirect straight to it # Assume it's a path and not a full URL, so make a full URL. # be sure we aren't returning to the login, register or logout page when logged in, or causing a loop # TODO - re-write this, it's not at all clear (and there are much better ways to express this, i.e.: # https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in,-sign-out,-sign-up,-update
default_uri_or_active_record_instance
<not_specific>