Disable notification in Devise Rails

I am using Devise for my Rails 3 application.

How to disable Devise warning messages for successful login activation?

+3


source to share


2 answers


You can:



  • Go to config \ locales \ devise.en.yml and change the lines you want to clear the lines (deleting them won't work). So, like this:

    sessions:
      signed_in: ''
      signed_out: ''
    
          

  • Or extend / override the development session controller. To do this, copy the action code to create

    and destroy

    from here and paste it into the controller (call its sessions) to inherit from the development session controller, for example:

    class SessionsController < Devise::SessionsController
    
          

    Then remove the calls to set_flash_message. Finally, edit your routes file for this change to take effect:

    devise_for :users, :controllers => { :sessions => 'sessions' }
    
          

+13


source


Based on what others have said, this way might be a little easier than extending development or something.

Be sure to use blank lines instead of deleting the entire line, otherwise the utility will revert to using the default for this message.

# blank out any string you don't want to render as a message
devise:
  failure:
    already_authenticated: ''
    unauthenticated: ''
    unconfirmed: ''
   ...

      

Now the developer will still pass the empty string as a flash alert. But now it will look something like this: the message will be an empty line



#<ActionDispatch::Flash::FlashHash:0xa7647c4
  @closed=false,
  @flashes={:alert=>""},
  @now=nil,
  @used=#<Set: {:alert}>>

      

I am using a helper method in my ApplicationHelper file that handles all messages together. You can do it differently, but it will give you the idea.

def all_messages

  # Standard flash messages
  messages = flash.map{|key,val| {:type=>key, :message=>val} unless val.blank? }.compact
    #                                                        |-------------------------|
    # This is where the magic happens. This is how I ignore any blank messages

  # Model validation errors
  model = instance_variable_get("@#{controller_name.singularize}")
  unless model.nil?
    messages += model.errors.full_messages.map do |msg|
      {:type=>:error, :message=>msg}
    end
  end

  return messages

end

      

And voila, the statement unless val.blank?

maps any empty value to nil, and the method .compact

removes any nil values, leaving you with a creaky clean array with no empty messages.

0


source







All Articles