Reputation: 45
I want to inform users of a new feedback feature the very next time they log in and never after that unless they opt the option of "Later maybe".
How can I achieve it? Thanks in advance.
Upvotes: 0
Views: 290
Reputation: 987
There are lots of ways to do it. I prefer this way:
Example:
# Migration
add_column :users, :notifications, arrray: true, default: []
# Create notification
User.update_all(%Q{notifications = array_append(notifications, "New alert")})
# Remove notification
current_user.notifications.pop
current_user.save
It could be customized, depending on what you need. For example, you can store only one notification as a string. Or you can create a table with notifications and store only ids of them in users table, if notifications are complex.
Upvotes: 2