Allow router_name to be customizable via Devise.router_name, useful for engines

This commit is contained in:
José Valim 2012-01-02 22:42:38 +01:00
parent 1ebcb09fc1
commit 897c1c684e
4 changed files with 18 additions and 5 deletions

View File

@ -9,8 +9,9 @@ Notes: https://@plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0
* Do not run validations unless on reconfirmable branch
* enhancements
* Allow parent controller to be customizable
* Inherit from the same Devise parent controller (by @sj26)
* Allow parent_controller to be customizable via Devise.parent_controller, useful for engines
* Allow router_name to be customizable via Devise.router_name, useful for engines
* deprecation
* Move devise/shared/_links.erb to devise/_links.erb

View File

@ -217,6 +217,12 @@ module Devise
mattr_accessor :parent_controller
@@parent_controller = "ApplicationController"
# The router Devise should use to generate routes. Defaults
# to :main_app. Should be overriden by engines in order
# to provide custom routes.
mattr_accessor :router_name
@@router_name = :main_app
# DEPRECATED CONFIG
# If true, uses salt as remember token and does not create it in the database.

View File

@ -39,7 +39,7 @@ module Devise
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
def #{method}(resource_or_scope, *args)
scope = Devise::Mapping.find_scope!(resource_or_scope)
send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args)
_devise_route_context.send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args)
end
URL_HELPERS
end
@ -48,6 +48,12 @@ module Devise
end
generate_helpers!(Devise::URL_HELPERS)
private
def _devise_route_context
@_devise_route_context ||= send(Devise.router_name)
end
end
end
end

View File

@ -92,7 +92,7 @@ module ActionDispatch::Routing
# Notice that whenever you use namespace in the router DSL, it automatically sets the module.
# So the following setup:
#
# namespace :publisher
# namespace :publisher do
# devise_for :account
# end
#
@ -369,13 +369,13 @@ module ActionDispatch::Routing
end
def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc:
old_as, old_path, old_module, old_constraints, old_defaults, old_options =
old_as, old_path, old_module, old_constraints, old_defaults, old_options =
*@scope.values_at(:as, :path, :module, :constraints, :defaults, :options)
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] =
new_as, new_path, nil, *options.values_at(:constraints, :defaults, :options)
yield
ensure
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] =
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] =
old_as, old_path, old_module, old_constraints, old_defaults, old_options
end