Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Demonstration of with_scope for class methods which operate on scoped records

View Notification.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 
class Notification < ActiveRecord::Base
 
belongs_to :user
 
scope :for_user, lambda { |user| where(:user_id => user.id) }
scope :unexpired, where('expired_at is null')
 
delf self.expire!
with_scope do
# Here we further filter by the `unexpired` scope,
# but the default scope is available as `scoped`
# and there is also an `unscoped` method.
unexpired.each &:expire!
end
end
def expire!
self.expired_at = Time.now
save!
end
 
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.