Skip to content

Instantly share code, notes, and snippets.

@jsuchal
Created January 21, 2015 18:19
Show Gist options
  • Save jsuchal/13de0e9148f55f6c5a66 to your computer and use it in GitHub Desktop.
Save jsuchal/13de0e9148f55f6c5a66 to your computer and use it in GitHub Desktop.
class Topic < ActiveRecord::Base
has_many :comments
has_one :last_comment, class_name: 'Comment'
end
class Comment < ActiveRecord::Base
belongs_to :topic
after_create :set_last_comment
def set_last_comment
topic.last_comment = self
topic.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment