metamaps--metamaps/app/models/star.rb

23 lines
572 B
Ruby
Raw Normal View History

2016-09-24 03:00:46 +00:00
# frozen_string_literal: true
2017-11-25 19:23:47 +00:00
class Star < ApplicationRecord
belongs_to :user
belongs_to :map
validates :map, uniqueness: { scope: :user, message: 'You have already starred this map' }
2017-11-25 19:23:47 +00:00
# after_create :after_created_async
# before_destroy :before_destroyed
protected
2017-11-25 19:23:47 +00:00
def after_created_async
FollowService.follow(map, user, 'starred')
NotificationService.notify_followers(map, 'map_starred', self, 'created')
end
handle_asynchronously :after_created_async
2017-11-25 19:23:47 +00:00
def before_destroyed
FollowService.remove_reason(map, user, 'starred')
end
end