views:

38

answers:

1

Suppose you want to show a message to a user who has logged in for the first time like, "Thanks for signing up".

Of course this is easy to achieve, but it seems a waste to check if it is their first visit (by any mechanism) every time thereafter.

Is it possible to do it in any way that doesn't involve checking every time?

I suppose this is more of a general programming question and not specific to rails.

A: 

If you are just showing that someone logged in for the first time, most authentication plugins I know of have a last_logged_in_at or equivalent that is set when they log in. You could check for when that is set from nil as your flag to send a message.

If you see yourself sending notifications consistently to the user (similar to SO), then you might have a notification model. You check for which notifications were not dismissed and then you aren't really going out of your way to send one message you are querying for any pending messages.

Geoff Lanotte
I might not have been very clear, sorry. Checking whether or not last_login_at == nil will have to be done every single time the user signs in. I wonder if there's a way to do something (anything) exactly once without having to do this check every time, given that we know when we want to do it. Maybe something that after execution deletes its tracks...
doctororange
I wish I had a good answer, I cannot think of a way to do something without looking for it first. I was just thinking of leveraging a process that you are already using. Best of luck!
Geoff Lanotte
You're quite right. Leveraging off some other check that is happening anyway is a good approach. Thanks :0)
doctororange