Rakesh Verma
Rakesh Verma

Reputation: 45

Notifying user of a new feature through one time notification in ruby on rails

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

Answers (1)

unkmas
unkmas

Reputation: 987

There are lots of ways to do it. I prefer this way:

  1. Add column to user with Array data-type
  2. When you need to show notifications, push this notification to all users
  3. When user saw it, remove it from Array

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

Related Questions