When users sign up to my application I have a welcome message appear on the home page using Devise’s sign_in_count column.
def home
if current_user.sign_in_count == 1
flash.now[:notice] = "Welcome!"
end
end
The only problem though is it stays there until they sign out and sign back in. How can I make it show only once and disappear when the page is refreshed or changed? Is there some rails way to do this?
Thank you.
EDIT
application.html.erb
<body>
<div class="container">
<%= render "shared/flash_message" %>
<%= yield %>
</div>
</body>
_flash_message.html.erb
<% [:notice, :error, :alert].each do |level| %>
<% unless flash[level].blank? %>
<div class="span12">
<div class="<%= flash_class(level) %> fade in">
<a href="#" data-dismiss="alert" class="close">×</a>
<%= content_tag :p, flash[level] %>
</div>
</div>
<% end %>
<% end %>
In your
layouts/application.html.erbyou should have something like this:Doing this way, should works as you expect.
EDIT
What if you verify for the
current_useris already set?EDIT 2
OK! Got it! The
sign_in_countcolumn fromDevisewill remain the same until the next login, so, it will always keep showing you theWelcome!message. To make this work as you expect you have to create a flag on it.You can try using
sessionorcookies.