Created
January 21, 2015 18:19
-
-
Save jsuchal/13de0e9148f55f6c5a66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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