diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index 863d562c..677fe6d1 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -67,6 +67,9 @@ module Devise @constraints = Hash.new { |h,k| h[k] = k.to_s } @constraints.merge!(options[:constraints] || {}) + @defaults = Hash.new { |h,k| h[k] = k.to_s } + @defaults.merge!(options[:defaults] || {}) + @sign_out_via = options[:sign_out_via] || Devise.sign_out_via end @@ -104,6 +107,10 @@ module Devise @constraints end + def defaults + @defaults + end + # Create magic predicates for verifying what module is activated by this map. # Example: # diff --git a/lib/devise/rails/routes.rb b/lib/devise/rails/routes.rb index a55df494..92f153c0 100644 --- a/lib/devise/rails/routes.rb +++ b/lib/devise/rails/routes.rb @@ -160,6 +160,7 @@ module ActionDispatch::Routing options[:path_prefix] ||= @scope[:path] if @scope[:path].present? options[:path_names] = (@scope[:path_names] || {}).merge(options[:path_names] || {}) options[:constraints] = (@scope[:constraints] || {}).merge(options[:constraints] || {}) + options[:defaults] = (@scope[:defaults] || {}).merge(options[:defaults] || {}) resources.map!(&:to_sym) @@ -186,7 +187,7 @@ module ActionDispatch::Routing devise_scope mapping.name do yield if block_given? - with_devise_exclusive_scope mapping.fullpath, mapping.name, mapping.constraints do + with_devise_exclusive_scope mapping.fullpath, mapping.name, mapping.constraints, mapping.defaults do routes.each { |mod| send("devise_#{mod}", mapping, mapping.controllers) } end end @@ -331,12 +332,12 @@ module ActionDispatch::Routing @scope[:path] = path end - def with_devise_exclusive_scope(new_path, new_as, new_constraints) #:nodoc: - old_as, old_path, old_module, old_constraints = @scope[:as], @scope[:path], @scope[:module], @scope[:constraints] - @scope[:as], @scope[:path], @scope[:module], @scope[:constraints] = new_as, new_path, nil, new_constraints + def with_devise_exclusive_scope(new_path, new_as, new_constraints, new_defaults) #:nodoc: + old_as, old_path, old_module, old_constraints, old_defaults = @scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults] + @scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults] = new_as, new_path, nil, new_constraints, new_defaults yield ensure - @scope[:as], @scope[:path], @scope[:module], @scope[:constraints] = old_as, old_path, old_module, old_constraints + @scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults] = old_as, old_path, old_module, old_constraints, old_defaults end def raise_no_devise_method_error!(klass) #:nodoc: