开发者

How to do something on user's first visit without checking subsequent visits in Rails

Suppose you want to show a message to a user who has logged in for the fir开发者_开发知识库st 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜