Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
class Reply < ActiveRecord::Base | ||
belongs_to :author, :class_name => "User" | ||
belongs_to :topic | ||
belongs_to :topic, :counter_cache => true | ||
|
||
after_create :set_topics_last_reply | ||
|
||
def mail_subject | ||
"Re: [Cuniculi Cavum] #{topic.subject}" | ||
end | ||
|
||
private | ||
|
||
# This has the convenient side-effect of refreshing Topic#updated_at for | ||
# the topic index's sorting. | ||
def set_topics_last_reply | ||
topic.update_attribute :last_reply, self | ||
end | ||
|
||
end |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class AddRepliesCountToTopics < ActiveRecord::Migration | ||
def self.up | ||
add_column :topics, :replies_count, :integer, :default => 0 | ||
end | ||
|
||
def self.down | ||
remove_column :topics, :replies_count | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class AddLastReplyToTopics < ActiveRecord::Migration | ||
def self.up | ||
add_column :topics, :last_reply_id, :integer | ||
end | ||
|
||
def self.down | ||
remove_column :topics, :last_reply_id | ||
end | ||
end |
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