diff options
| author | mo khan <mo@mokhan.ca> | 2014-11-01 22:16:32 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-11-01 22:16:32 -0600 |
| commit | dd111d3a4a91ca16256f11ad9f7d225aaf1d0f01 (patch) | |
| tree | 36f9a10723720c5a8bb0ad13d33157631e6b9e35 /app/models | |
| parent | 90db48fb5cf1c3d0e55136f7931bf93ef7fefb9b (diff) | |
manually notifiy user when a new activity has been created and recreate all activities.
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/activity.rb | 9 | ||||
| -rw-r--r-- | app/models/comment.rb | 5 | ||||
| -rw-r--r-- | app/models/favorite.rb | 5 | ||||
| -rw-r--r-- | app/models/user.rb | 4 |
4 files changed, 14 insertions, 9 deletions
diff --git a/app/models/activity.rb b/app/models/activity.rb index 24e5ebb0..0e3047cd 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -1,9 +1,4 @@ class Activity < ActiveRecord::Base - belongs_to :subject, polymorphic: true - belongs_to :user - after_create :send_notification_email - - def send_notification_email - NotificationMailer.delay.notification_email(self) - end + belongs_to :subject, polymorphic: true # favorite, comment + belongs_to :user # user to notify end diff --git a/app/models/comment.rb b/app/models/comment.rb index 464d05f9..f85bc343 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -7,6 +7,9 @@ class Comment < ActiveRecord::Base private def create_activity - Activity.create(user: user, subject: self) + transaction do + Activity.create(user: creation.author, subject: self) + creation.author.notify_of_activity + end end end diff --git a/app/models/favorite.rb b/app/models/favorite.rb index 2a6e900d..289d83ad 100644 --- a/app/models/favorite.rb +++ b/app/models/favorite.rb @@ -4,6 +4,9 @@ class Favorite < ActiveRecord::Base after_create :create_activity def create_activity - Activity.create(user: creation.author, subject: self) + transaction do + Activity.create(user: creation.author, subject: self) + creation.author.notify_of_activity + end end end diff --git a/app/models/user.rb b/app/models/user.rb index 6b152a84..edaf11c2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -65,6 +65,10 @@ class User < ActiveRecord::Base creations.create(name: name, category_id: category.id) end + def notify_of_activity + NotificationMailer.delay.notification_email(self) + end + class << self def login(username, password) user = User.find_by(email: username) |
