diff --git a/app/controllers/devise/confirmations_controller.rb b/app/controllers/devise/confirmations_controller.rb index a6a4a880..a728f7ea 100644 --- a/app/controllers/devise/confirmations_controller.rb +++ b/app/controllers/devise/confirmations_controller.rb @@ -20,7 +20,7 @@ class Devise::ConfirmationsController < DeviseController self.resource = resource_class.confirm_by_token(params[:confirmation_token]) if resource.errors.empty? - set_flash_message(:notice, :confirmed) if is_navigational_format? + set_flash_message(:notice, :confirmed) if is_flashing_format? respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) } else respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new } diff --git a/app/controllers/devise/passwords_controller.rb b/app/controllers/devise/passwords_controller.rb index 4cb353aa..6ecc772b 100644 --- a/app/controllers/devise/passwords_controller.rb +++ b/app/controllers/devise/passwords_controller.rb @@ -32,7 +32,7 @@ class Devise::PasswordsController < DeviseController if resource.errors.empty? resource.unlock_access! if unlockable?(resource) flash_message = resource.active_for_authentication? ? :updated : :updated_not_active - set_flash_message(:notice, flash_message) if is_navigational_format? + set_flash_message(:notice, flash_message) if is_flashing_format? sign_in(resource_name, resource) respond_with resource, :location => after_resetting_password_path_for(resource) else diff --git a/app/controllers/devise/registrations_controller.rb b/app/controllers/devise/registrations_controller.rb index d8a4d4ce..22406ad8 100644 --- a/app/controllers/devise/registrations_controller.rb +++ b/app/controllers/devise/registrations_controller.rb @@ -14,11 +14,11 @@ class Devise::RegistrationsController < DeviseController if resource.save if resource.active_for_authentication? - set_flash_message :notice, :signed_up if is_navigational_format? + set_flash_message :notice, :signed_up if is_flashing_format? sign_up(resource_name, resource) respond_with resource, :location => after_sign_up_path_for(resource) else - set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format? + set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format? expire_session_data_after_sign_in! respond_with resource, :location => after_inactive_sign_up_path_for(resource) end @@ -41,7 +41,7 @@ class Devise::RegistrationsController < DeviseController prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email) if update_resource(resource, account_update_params) - if is_navigational_format? + if is_flashing_format? flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ? :update_needs_confirmation : :updated set_flash_message :notice, flash_key @@ -58,7 +58,7 @@ class Devise::RegistrationsController < DeviseController def destroy resource.destroy Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name) - set_flash_message :notice, :destroyed if is_navigational_format? + set_flash_message :notice, :destroyed if is_flashing_format? respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) } end diff --git a/app/controllers/devise/sessions_controller.rb b/app/controllers/devise/sessions_controller.rb index a9b3922e..87dc5b54 100644 --- a/app/controllers/devise/sessions_controller.rb +++ b/app/controllers/devise/sessions_controller.rb @@ -13,7 +13,7 @@ class Devise::SessionsController < DeviseController # POST /resource/sign_in def create self.resource = warden.authenticate!(auth_options) - set_flash_message(:notice, :signed_in) if is_navigational_format? + set_flash_message(:notice, :signed_in) if is_flashing_format? sign_in(resource_name, resource) respond_with resource, :location => after_sign_in_path_for(resource) end @@ -22,7 +22,7 @@ class Devise::SessionsController < DeviseController def destroy redirect_path = after_sign_out_path_for(resource_name) signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)) - set_flash_message :notice, :signed_out if signed_out && is_navigational_format? + set_flash_message :notice, :signed_out if signed_out && is_flashing_format? # We actually need to hardcode this as Rails default responder doesn't # support returning empty response on GET request diff --git a/app/controllers/devise/unlocks_controller.rb b/app/controllers/devise/unlocks_controller.rb index 539d9741..7194755e 100644 --- a/app/controllers/devise/unlocks_controller.rb +++ b/app/controllers/devise/unlocks_controller.rb @@ -22,7 +22,7 @@ class Devise::UnlocksController < DeviseController self.resource = resource_class.unlock_access_by_token(params[:unlock_token]) if resource.errors.empty? - set_flash_message :notice, :unlocked if is_navigational_format? + set_flash_message :notice, :unlocked if is_flashing_format? respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) } else respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new } diff --git a/app/controllers/devise_controller.rb b/app/controllers/devise_controller.rb index 65822b03..b1b88b74 100644 --- a/app/controllers/devise_controller.rb +++ b/app/controllers/devise_controller.rb @@ -123,7 +123,7 @@ MESSAGE end if notice - set_flash_message :notice, notice if is_navigational_format? + set_flash_message :notice, notice if is_flashing_format? true end end diff --git a/lib/devise.rb b/lib/devise.rb index 99e585df..69b282fa 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -209,6 +209,10 @@ module Devise mattr_accessor :navigational_formats @@navigational_formats = ["*/*", :html] + # Which formats should display flash messages. + mattr_accessor :flashing_formats + @@flashing_formats = nil + # When set to true, signing out a user signs out all other scopes. mattr_accessor :sign_out_all_scopes @@sign_out_all_scopes = true diff --git a/lib/devise/controllers/helpers.rb b/lib/devise/controllers/helpers.rb index 5d3e908c..ab14551e 100644 --- a/lib/devise/controllers/helpers.rb +++ b/lib/devise/controllers/helpers.rb @@ -291,6 +291,10 @@ module Devise Devise.navigational_formats.include?(request_format) end + def is_flashing_format? + (Devise.flashing_formats || Devise.navigational_formats).include?(request_format) + end + private def expire_devise_cached_variables! diff --git a/lib/generators/templates/devise.rb b/lib/generators/templates/devise.rb index ab0e8c0e..802cd3f4 100644 --- a/lib/generators/templates/devise.rb +++ b/lib/generators/templates/devise.rb @@ -221,6 +221,10 @@ Devise.setup do |config| # The "*/*" below is required to match Internet Explorer requests. # config.navigational_formats = ['*/*', :html] + # Lists the formats that should display flash messages. Inherits + # navigational_formats if falsy + # config.flashing_formats = nil + # The default HTTP method used to sign out a resource. Default is :delete. config.sign_out_via = :delete diff --git a/test/rails_app/config/initializers/devise.rb b/test/rails_app/config/initializers/devise.rb index 84031881..3682bb6b 100644 --- a/test/rails_app/config/initializers/devise.rb +++ b/test/rails_app/config/initializers/devise.rb @@ -162,6 +162,10 @@ Devise.setup do |config| # should add them to the navigational formats lists. Default is [:html] # config.navigational_formats = [:html, :iphone] + # Lists the formats that should display flash messages. Inherits + # navigational_formats if falsy + # config.flashing_formats = nil + # The default HTTP method used to sign out a resource. Default is :get. # config.sign_out_via = :get