Skip to content

Commit

Permalink
Resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason L Perry committed Apr 2, 2009
2 parents 095d87f + e0dbcc7 commit 5db2665
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/topics_controller.rb
Expand Up @@ -6,7 +6,7 @@ class TopicsController < ApplicationController
# GET /topics
# GET /topics.xml
def index
@topics = Topic.paginate :per_page => 10, :page => params[:page], :order => "created_at DESC"
@topics = Topic.paginate :per_page => 10, :page => params[:page], :order => "updated_at DESC"

respond_to do |format|
format.html # index.html.erb
Expand Down
12 changes: 11 additions & 1 deletion app/models/reply.rb
@@ -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
1 change: 1 addition & 0 deletions app/models/topic.rb
@@ -1,5 +1,6 @@
class Topic < ActiveRecord::Base
belongs_to :author, :class_name => "User"
belongs_to :last_reply, :class_name => "Reply"
has_many :replies

def mail_subject
Expand Down
7 changes: 6 additions & 1 deletion app/views/topics/index.html.erb
Expand Up @@ -3,7 +3,12 @@
<div class="authorship">
posted by <%= link_to h(topic.author.name), topic.author %></a>
<%= time_ago_in_words(topic.created_at) %> ago
(<%= topic.replies.count %> <%= topic.replies.count == 1 ? "reply" : "replies" %>)
(<%= topic.replies.count -%>
<%= topic.replies.count == 1 ? "reply" : "replies" -%>
<%- if topic.last_reply -%>, last one by
<%= link_to h(topic.last_reply.author.name), topic.last_reply.author %>
<%= time_ago_in_words(topic.last_reply.created_at) %> ago
<%- end -%>)
</div>

<h2><%= link_to h(topic.subject), topic %></h2>
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20090316152049_add_replies_count_to_topics.rb
@@ -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
9 changes: 9 additions & 0 deletions db/migrate/20090330040325_add_last_reply_to_topics.rb
@@ -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
2 changes: 2 additions & 0 deletions db/schema.rb
Expand Up @@ -75,6 +75,8 @@
t.text "body"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "replies_count", :default => 0
t.integer "last_reply_id"
end

create_table "users", :force => true do |t|
Expand Down

0 comments on commit 5db2665

Please sign in to comment.