Sha256: c0c10b13c00dd972ff8b7ce6d3d286f8d0748bcb45ca5fed92a0b37c31f104bf
Contents?: true
Size: 1.32 KB
Versions: 3
Compression:
Stored size: 1.32 KB
Contents
module ActionDispatch::Routing class Mapper module ApplicationRedirector # # Provide a redirect helper which allows the user to redirect # to an application relative url. # # Usage (in routes.rb): # # match 'power' => app_redirect('platform') # match 'email_confirm_express' => app_redirect {|p, req| "email_confirm?#{req.query_string}"} # # will generate a redirect from /<appbaseuri>/power to /<appbaseuri>/platform, regardless of # whether Rails is run as a root site or as a subsite. Should respond to the same arguments as # redirect. # def app_redirect(*args, &block) options = args.last.is_a?(Hash) ? args.pop : {} path = args.shift || block path_proc = path.is_a?(Proc) ? path : lambda do |params| path % params end block = lambda do |params, req| newargs = [params] newargs << req if path_proc.arity > 1 uri = URI.join('http://localhost', "#{req.script_name}/", path_proc.call(*newargs)) Rails.logger.debug "URI #{uri}, #{req.script_name}" if uri.host == 'localhost' uri.request_uri else uri end end redirect(block, options) end end include ApplicationRedirector end end
Version data entries
3 entries across 3 versions & 1 rubygems