Skip to content

Instantly share code, notes, and snippets.

@loss-zz
Created September 8, 2011 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loss-zz/1202726 to your computer and use it in GitHub Desktop.
Save loss-zz/1202726 to your computer and use it in GitHub Desktop.
post.rb
class Post < ActiveRecord::Base
belongs_to :user
belongs_to :topic, :counter_cache => true, :touch => :last_updated_at
scope :major, where(:major=>true)
scope :reply, where(:major=>false)
validates_presence_of :body
after_create :update_cached_fields
protected
def update_cached_fields
topic.update_cached_post_fields(self) unless self.major
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment