Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails/Devise - Customize flash message (devise.en.yml) with a link_to

I would like to customize the following flash msg provided by devise in the devise.en.yml file:

devise:
   failure:
      unconfirmed: 'You have to confirm your account before continuing.'

with ruby code in order to get a link to new_user_confirmation_path.

in other words, I want my flash message displays something like :

'You have to confirm your account before continuing. Didn't receive confirmation instructions?'

where 'Didn't receive confirmation instructions?' is a link to new_user_confirmation_path.

I would like to know if I can do this without editing the user controller cause Devise doesn't provide it by default.

Thanks for your answer!

like image 904
benoitr Avatar asked Oct 24 '10 11:10

benoitr


Video Answer


1 Answers

new_user_confirmation_path is a static url equivalent to /users/confirmation/new

So you can just do this in your devise.en.yml file:

devise:
  failure:
    unconfirmed: "You have to confirm your account before continuing. <a href='/users/confirmation/new'>Didn't receive confirmation instructions?</a>"

In the controller actions where you display your flash make sure you have .html_safe e.g. flash[:error].html_safe

like image 161
Nada Aldahleh Avatar answered Sep 28 '22 03:09

Nada Aldahleh