Skip to content

Commit

Permalink
Devise::Controller::Generator added for auto-generating controllers b…
Browse files Browse the repository at this point in the history
…ased on scope(s) & other fixes for same
  • Loading branch information
Bharat311 committed Jan 7, 2014
1 parent b9cddbd commit cd308ff
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Devise
autoload :TokenGenerator, 'devise/token_generator'

module Controllers
autoload :Generator, 'devise/controllers/generator'

This comment has been minimized.

Copy link
@josevalim

josevalim Jan 7, 2014

Is the generator file missing?

This comment has been minimized.

Copy link
@Bharat311

Bharat311 Jan 7, 2014

Author Owner

just added it in the latest commit

autoload :Helpers, 'devise/controllers/helpers'
autoload :Rememberable, 'devise/controllers/rememberable'
autoload :ScopedViews, 'devise/controllers/scoped_views'
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/devise/controllers/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/devise/mailers/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

This comment has been minimized.

Copy link
@josevalim

josevalim Jan 7, 2014

Why do we need this line? :) Shouldn't it be handled by the engine inheritance?

This comment has been minimized.

Copy link
@Bharat311

Bharat311 Jan 7, 2014

Author Owner

This line is added to allow for each engine to have its own mail templates. Not sure about the engine inheritance, though.

template_path.unshift "#{@devise_mapping.scoped_path}/mailer" if self.class.scoped_views?
template_path
end
Expand Down
7 changes: 7 additions & 0 deletions lib/devise/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cd308ff

Please sign in to comment.