include target for notification

This commit is contained in:
zhitomirskiyi 2011-01-18 17:06:54 -08:00
parent 38a3193a61
commit e7a4c47f0a
2 changed files with 2 additions and 3 deletions

View file

@ -18,7 +18,7 @@ class NotificationsController < ApplicationController
end end
def index def index
@notifications = Notification.for(current_user).paginate :page => params[:page], :per_page => 25 @notifications = Notification.for(current_user).include(:target).paginate :page => params[:page], :per_page => 25
@group_days = @notifications.group_by{|note| note.created_at.strftime("%B %d") } @group_days = @notifications.group_by{|note| note.created_at.strftime("%B %d") }
respond_with @notifications respond_with @notifications
end end
@ -27,5 +27,4 @@ class NotificationsController < ApplicationController
Notification.where(:recipient_id => current_user.id).update_all(:unread => false) Notification.where(:recipient_id => current_user.id).update_all(:unread => false)
redirect_to :back redirect_to :back
end end
end end

View file

@ -11,7 +11,7 @@ class Notification < ActiveRecord::Base
belongs_to :target, :polymorphic => true belongs_to :target, :polymorphic => true
def self.for(recipient, opts={}) def self.for(recipient, opts={})
self.where(opts.merge!(:recipient_id => recipient.id)).order('created_at desc') self.where(opts.merge!(:recipient_id => recipient.id)).order('created_at desc').include(:target)
end end
def self.notify(recipient, target, actor) def self.notify(recipient, target, actor)