diff --git a/lib/devise.rb b/lib/devise.rb index f4492dbc65..022f2680d2 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -17,6 +17,7 @@ module Devise autoload :TokenGenerator, 'devise/token_generator' module Controllers + autoload :Generator, 'devise/controllers/generator' autoload :Helpers, 'devise/controllers/helpers' autoload :Rememberable, 'devise/controllers/rememberable' autoload :ScopedViews, 'devise/controllers/scoped_views' @@ -294,7 +295,7 @@ def self.#{method}=(val) # If within the same application, Devise is to be mounted on different engines. mattr_accessor :controller_scopes - @@controller_scopes = :devise + @@controller_scopes = [:devise] # Default way to setup Devise. Run rails generate devise_install to create # a fresh initializer with all configuration values. diff --git a/lib/devise/controllers/helpers.rb b/lib/devise/controllers/helpers.rb index a0ea0edf24..e995423ad2 100644 --- a/lib/devise/controllers/helpers.rb +++ b/lib/devise/controllers/helpers.rb @@ -79,7 +79,7 @@ def warden # # before_filter :my_filter, :unless => :devise_controller? def devise_controller? - is_a?(DeviseController) + self.class.included_modules.include?(::Devise::Mixins::Base) end # Setup a param sanitizer to filter parameters using strong_parameters. See diff --git a/lib/devise/mailers/helpers.rb b/lib/devise/mailers/helpers.rb index 06cd4b42de..b0f8825d02 100644 --- a/lib/devise/mailers/helpers.rb +++ b/lib/devise/mailers/helpers.rb @@ -60,6 +60,7 @@ def mailer_sender(mapping, sender = :from) def template_paths template_path = _prefixes.dup + template_path.unshift "#{Devise.router_name}/devise/mailer" if Devise.router_name template_path.unshift "#{@devise_mapping.scoped_path}/mailer" if self.class.scoped_views? template_path end diff --git a/lib/devise/rails.rb b/lib/devise/rails.rb index 70e79f84ac..d75c5c5058 100644 --- a/lib/devise/rails.rb +++ b/lib/devise/rails.rb @@ -13,6 +13,13 @@ class Engine < ::Rails::Engine # Force routes to be loaded if we are doing any eager load. config.before_eager_load { |app| app.reload_routes! } + # Generate the Devise's Controllers (per request for development & once for production) for all the specified controller_scopes. + config.to_prepare do + Devise.controller_scopes.each do |scope| + Devise::Controllers::Generator.generate scope + end + end + initializer "devise.url_helpers" do Devise.include_helpers(Devise::Controllers) end