Skip to content

Instantly share code, notes, and snippets.

@Orion98MC
Created December 6, 2010 12:34
Show Gist options
  • Save Orion98MC/730226 to your computer and use it in GitHub Desktop.
Save Orion98MC/730226 to your computer and use it in GitHub Desktop.
class Notification < ActiveRecord::Base
serialize :device_ids # weak reference to devices
validates_presence_of :message
default_scope order("created_at DESC")
scope :ready, where("ready == ?", true)
scope :sent, where("sent_at IS NOT NULL")
scope :not_sent, where("sent_at IS NULL")
scope :sendable, not_sent.ready
scope :old, lambda{ where("updated_at < ?", 10.days.ago) }
scope :deletable, old.sent
def self.per_page; 10;end
end
controller action:
def notifications
@notifications = Notification.not_sent.paginate(:page => params[:page])
render
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment