Question

I am using Devise gem for user authentication with confirmable (Email confirmation). I want to display a tour button on home page only after user signup but not on login. Iam doing something like this

    <% if current_user && current_user.confirmed_at_changed? && session[:tour].blank? %>
   <% session[:tour] = true %>
    <div id="outsider">
      <button id="startTourBtn" class="btn btn-large btn-primary">Take a tour</button>
    </div>
<%end%>

But this is not working..... Thanks in advance for any suggestion, advise.

Was it helpful?

Solution

Finally found it thanks to devise I can use the sign_in_count to display the button only for signed up users and not for logged in users by checking (current_user.sign_in_count == 1).And it will shown only once :)

  <% if current_user && !current_user.sign_in_count.blank? && current_user.sign_in_count == 1 && session[:tour].blank? %>
    <% session[:tour] = true %>
    <div id="outsider">
      <button id="startTourBtn" class="btn btn-large btn-primary">Take a tour</button>
    </div>
<%end%>

OTHER TIPS

If your users cannot sign in with not confirmed emails then you could just check if current_user present or use user_signed_in? devise's helper method.

<% if user_signed_in? %>
   ...
<% end %>

https://github.com/plataformatec/devise#controller-filters-and-helpers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top