Customize Devise Flash Message Content in Rails

Devise automatically includes great flash messages, however sometimes you want to edit or make your own.  In my case I have customized the devise controller for registrations, and I want to call a flash message in my custom devise registrations controller. (refer to my post on how to override and create a custom devise controller here).

So by looking in the devise source code, in particular the registrations_controller.rb, we see how to do this. First, in the devise.en.yml file, create your custom flash message content in the right location. In my case I want it to be in the registrations controller, so in the devise.en.yml under registrations I created a new flash message like this:

  wrong_beta_password: "You need the beta password to create an account." # this one is my custom one
  # Devise default flash messages here

Now, simply call this message in your custom devise controller:

set_flash_message :notice, :wrong_beta_password if is_flashing_format?

That’s it!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: