diff --git a/lib/devise.rb b/lib/devise.rb index c3bcdc9f..02a44eee 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -16,6 +16,7 @@ module Devise autoload :InternalHelpers, 'devise/controllers/internal_helpers' autoload :Rememberable, 'devise/controllers/rememberable' autoload :ScopedViews, 'devise/controllers/scoped_views' + autoload :SharedHelpers, 'devise/controllers/shared_helpers' autoload :UrlHelpers, 'devise/controllers/url_helpers' end diff --git a/lib/devise/controllers/internal_helpers.rb b/lib/devise/controllers/internal_helpers.rb index 86ad80db..92278665 100644 --- a/lib/devise/controllers/internal_helpers.rb +++ b/lib/devise/controllers/internal_helpers.rb @@ -6,19 +6,7 @@ module Devise module InternalHelpers #:nodoc: extend ActiveSupport::Concern include Devise::Controllers::ScopedViews - - MIME_REFERENCES = Mime::HTML.respond_to?(:ref) - - # Helper used by FailureApp and Devise controllers to retrieve proper formats. - def self.request_format(request) - if request.format.respond_to?(:ref) - request.format.ref - elsif MIME_REFERENCES - request.format - elsif request.format # Rails < 3.0.4 - request.format.to_sym - end - end + include Devise::Controllers::SharedHelpers included do helper DeviseHelper @@ -65,10 +53,6 @@ module Devise protected - def request_format - @request_format ||= Devise::Controllers::InternalHelpers.request_format(request) - end - # Checks whether it's a devise mapped resource or not. def is_devise_resource? #:nodoc: unknown_action! <<-MESSAGE unless devise_mapping @@ -81,11 +65,6 @@ Maybe you forgot to wrap your route inside the scope block? For example: MESSAGE end - # Check whether it's navigational format, such as :html or :iphone, or not. - def is_navigational_format? - Devise.navigational_formats.include?(request_format) - end - # Returns real navigational formats which are supported by Rails def navigational_formats @navigational_formats ||= Devise.navigational_formats.select{ |format| Mime::EXTENSION_LOOKUP[format.to_s] } diff --git a/lib/devise/controllers/shared_helpers.rb b/lib/devise/controllers/shared_helpers.rb new file mode 100644 index 00000000..cf0954b8 --- /dev/null +++ b/lib/devise/controllers/shared_helpers.rb @@ -0,0 +1,26 @@ +module Devise + module Controllers + # Helpers used in both FailureApp and Devise controllers. + module SharedHelpers + MIME_REFERENCES = Mime::HTML.respond_to?(:ref) + + protected + + # Helper used by FailureApp and Devise controllers to retrieve proper formats. + def request_format + @request_format ||= if request.format.respond_to?(:ref) + request.format.ref + elsif MIME_REFERENCES + request.format + elsif request.format # Rails < 3.0.4 + request.format.to_sym + end + end + + # Check whether it's navigational format, such as :html or :iphone, or not. + def is_navigational_format? + Devise.navigational_formats.include?(request_format) + end + end + end +end \ No newline at end of file diff --git a/lib/devise/failure_app.rb b/lib/devise/failure_app.rb index e69c5a47..578fcecc 100644 --- a/lib/devise/failure_app.rb +++ b/lib/devise/failure_app.rb @@ -10,6 +10,7 @@ module Devise include ActionController::UrlFor include ActionController::Redirecting include Rails.application.routes.url_helpers + include Devise::Controllers::SharedHelpers delegate :flash, :to => :request @@ -83,7 +84,7 @@ module Devise if request.xhr? Devise.http_authenticatable_on_xhr else - !(request_format && Devise.navigational_formats.include?(request_format)) + !(request_format && is_navigational_format?) end end @@ -135,9 +136,5 @@ module Devise def store_location! session["#{scope}_return_to"] = attempted_path if request.get? && !http_auth? end - - def request_format - @request_format ||= Devise::Controllers::InternalHelpers.request_format(request) - end end end