Rails 3 w/ Devise: How to show message on all pages if user hasn't confirmed email address?

690 views Asked by At

I am developing a Rails 3 app using the Devise gem for authentication. I'm also using the confirmable module of Devise to send emails to users when they sign up, asking them to confirm their email address.

I am allowing users to sign in even if they didn't confirm their email address (for a maximum of 20 days), however I want to display a message at the top of every page reminding them they didn't confirm their email address and that they can still login without doing so for X number of days.

Any ideas of how I should approach this? (i.e. any useful gems or tips)

Thanks very much !!!

1

There are 1 answers

0
iwasrobbed On BEST ANSWER

Looking at the docs here: http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Confirmable

It seems there is a confirmed? method that you can call on the User object to see if they are confirmed or not.

So I would just put a check for the confirmation in your views/layouts/application.html.erb file:

<% if user_signed_in? && !current_user.confirmed? %>
  <div>
    Please confirm your account by clicking the link in the email we sent to <%= current_user.email %>
  </div>
<% end %>