Search code examples
ruby-on-railsdeviseruby-on-rails-5flash-message

How do I create a custom flash message for Devise?


I tried the following but it's not working. It's still using the default flash message.

class Users::SessionsController < Devise::SessionsController
  after_action :custom_welcome, :only => [:create]

  def custom_welcome
    flash.notice = "Welcome back "+current_user.name+"." if flash.keys.include?(:notice)
  end
end

Reference: https://github.com/plataformatec/devise#configuring-controllers

https://stackoverflow.com/a/5513172/148844


Solution

  • This worked.

    flash.notice = "Welcome back #{current_user.name}." if flash.key?(:notice)