mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Do not always skip helpers, instead provide :skip_helpers as option to trigger it manually
This commit is contained in:
parent
ef4eb47d50
commit
8796c1c601
5 changed files with 28 additions and 7 deletions
|
@ -1,3 +1,6 @@
|
|||
* bug fix
|
||||
* Do not always skip helpers, instead provide :skip_helpers as option to trigger it manually
|
||||
|
||||
== 1.4.3
|
||||
|
||||
* enhancements
|
||||
|
|
|
@ -25,7 +25,7 @@ module Devise
|
|||
end
|
||||
|
||||
def self.generate_helpers!
|
||||
mappings = Devise.mappings.values.map(&:used_routes).flatten.uniq
|
||||
mappings = Devise.mappings.values.map(&:used_helpers).flatten.uniq
|
||||
routes = Devise::URL_HELPERS.slice(*mappings)
|
||||
|
||||
routes.each do |module_name, actions|
|
||||
|
|
|
@ -23,7 +23,7 @@ module Devise
|
|||
#
|
||||
class Mapping #:nodoc:
|
||||
attr_reader :singular, :scoped_path, :path, :controllers, :path_names,
|
||||
:class_name, :sign_out_via, :format, :used_routes
|
||||
:class_name, :sign_out_via, :format, :used_routes, :used_helpers
|
||||
alias :name :singular
|
||||
|
||||
# Receives an object and find a scope for it. If a scope cannot be found,
|
||||
|
@ -74,11 +74,21 @@ module Devise
|
|||
@sign_out_via = options[:sign_out_via] || Devise.sign_out_via
|
||||
@format = options[:format]
|
||||
|
||||
@used_routes = self.routes
|
||||
singularizer = lambda { |s| s.to_s.singularize.to_sym }
|
||||
|
||||
if options.has_key?(:only)
|
||||
@used_routes = Array(options.delete(:only)).map { |s| s.to_s.singularize.to_sym } & @used_routes
|
||||
@used_routes = self.routes & Array(options[:only]).map(&singularizer)
|
||||
else
|
||||
@used_routes = self.routes - Array(options[:skip]).map(&singularizer)
|
||||
end
|
||||
|
||||
if options[:skip_helpers] == true
|
||||
@used_helpers = @used_routes
|
||||
elsif skip = options[:skip_helpers]
|
||||
@used_helpers = self.routes - Array(skip).map(&singularizer)
|
||||
else
|
||||
@used_helpers = self.routes
|
||||
end
|
||||
@used_routes -= Array(options.delete(:skip)).map { |s| s.to_s.singularize.to_sym }
|
||||
end
|
||||
|
||||
# Return modules for the mapping.
|
||||
|
|
|
@ -104,6 +104,14 @@ module ActionDispatch::Routing
|
|||
#
|
||||
# devise_for :users, :only => :sessions
|
||||
#
|
||||
# * :skip_helpers => skip generating Devise url helpers like new_session_path(@user).
|
||||
# This is useful to avoid conflicts with previous routes and is false by default.
|
||||
# It accepts true as option, meaning it will skip all the helpers for the controllers
|
||||
# given in :skip but it also accepts specific helpers to be skipped:
|
||||
#
|
||||
# devise_for :users, :skip => [:registrations, :confirmations], :skip_helpers => true
|
||||
# devise_for :users, :skip_helpers => [:registrations, :confirmations]
|
||||
#
|
||||
# * :format => include "(.:format)" in the generated routes? true by default, set to false to disable:
|
||||
#
|
||||
# devise_for :users, :format => false
|
||||
|
|
|
@ -52,8 +52,8 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
# Routes for format=false testing
|
||||
devise_for :htmlonly_admin, :class_name => "Admin", :skip => [:confirmations, :unlocks], :path => "htmlonly_admin", :format => false
|
||||
devise_for :htmlonly_users, :class_name => "User", :only => [:confirmations, :unlocks], :path => "htmlonly_users", :format => false
|
||||
devise_for :htmlonly_admin, :class_name => "Admin", :skip => [:confirmations, :unlocks], :path => "htmlonly_admin", :format => false, :skip_helpers => [:confirmations, :unlocks]
|
||||
devise_for :htmlonly_users, :class_name => "User", :only => [:confirmations, :unlocks], :path => "htmlonly_users", :format => false, :skip_helpers => true
|
||||
|
||||
# Other routes for routing_test.rb
|
||||
devise_for :reader, :class_name => "User", :only => :passwords
|
||||
|
|
Loading…
Add table
Reference in a new issue