Skip to content

Commit

Permalink
Code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
skovachev committed May 24, 2015
1 parent bda8425 commit 68c5d28
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
3 changes: 1 addition & 2 deletions app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ def index

def show
notification = Notification.find params[:id]
notification.is_read = true
notification.save
Notification.mark_as_read notification
redirect_to notification.source
end
end
18 changes: 9 additions & 9 deletions app/models/generates_notifications.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module GeneratesNotifications
extend self
extend self

def generate_notifications_for(users, title:)
users.each do |user|
notification = Notification.new
notification.title = title
notification.source = self
notification.user = user
notification.save
end
def generate_notifications_for(users, title:)
users.find_each do |user|
notification = Notification.new
notification.title = title
notification.source = self
notification.user = user
notification.save!
end
end
end
5 changes: 5 additions & 0 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ class << self
def unread_for_user(id)
where(user_id: id, is_read: false)
end

def mark_as_read(notification)
notification.is_read = true
notification.save!
end
end
end

0 comments on commit 68c5d28

Please sign in to comment.