Skip to content

Commit

Permalink
Use the finished named_scope in a couple of places that were missing …
Browse files Browse the repository at this point in the history
…it. When marking a post as finished we must then do find_latest_post.
  • Loading branch information
radar committed Oct 25, 2009
1 parent 49ff3b1 commit 2150823
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
8 changes: 5 additions & 3 deletions app/models/post.rb
Expand Up @@ -31,7 +31,6 @@ class Post < ActiveRecord::Base
after_create :log_ip
after_create :update_forum
before_create :stop_spam
after_create :find_latest_post
after_destroy :find_latest_post

before_create :increment_counter
Expand Down Expand Up @@ -89,8 +88,11 @@ def find_latest_post
end

def finished!
self.finished = true
save!
unless finished?
self.finished = true
update_latest_post(post)
save!
end
end

def editor
Expand Down
6 changes: 4 additions & 2 deletions app/models/topic.rb
Expand Up @@ -71,8 +71,10 @@ def to_s
end

def finished!
self.finished = true
save!
unless finished?
self.finished = true
save!
end
end

def move!(new_forum_id, leave_redirect=false)
Expand Down
4 changes: 2 additions & 2 deletions app/views/forums/show.html.erb
Expand Up @@ -79,14 +79,14 @@
<%= will_paginate(topic.posts.paginate(:per_page => per_page, :page => 1), :prev_label => nil, :next_label => "", :params => { :controller => "topics", :action => "show", :id => topic.id, :forum_id => @forum.id }) %>
</b>
</td>
<td align='center'><%= (topic.moved? ? topic.moved_to.posts.count : topic.posts.count) - 1 %></td>
<td align='center'><%= (topic.moved? ? topic.moved_to.posts.finished.count : topic.posts.finished.count) - 1 %></td>
<td align='center'><%= topic.views %></td>
<td align='center'><%= link_to(h(topic.user), topic.user) %></td>
<td align='right' width='15%'>
<% if topic.moved? %>
-
<% else %>
<%= time_ago_in_words(topic.posts.last.created_at) %> <%= t(:ago) %> <%= t(:by) %> <%= link_to h(topic.last_post.user), topic.last_post.user %>
<%= time_ago_in_words(topic.posts.finished.last.created_at) %> <%= t(:ago) %> <%= t(:by) %> <%= link_to h(topic.last_post.user), topic.last_post.user %>
<% end %>
</td>
</tr>
Expand Down
4 changes: 2 additions & 2 deletions app/views/forums/show.rss.builder
Expand Up @@ -4,12 +4,12 @@ xml.rss :version => "2.0" do
xml.title @forum.title
xml.description @forum.description
xml.link forum_url(@forum, :format => :rss)
for post in @forum.posts.all(:limit => 50)
for post in @forum.posts.finished.all(:limit => 50)
xml.item do
xml.title post.subject
xml.description post.text
xml.pubDate post.created_at.to_s(:rfc822)
page = (post.topic.posts.count.to_f / per_page).ceil
page = (post.topic.posts.finished.count.to_f / per_page).ceil
xml.link forum_topic_path(post.forum, post.topic, :page => page) + "#post_#{post.id}"
xml.guid forum_topic_path(post.forum, post.topic, :page => page) + "#post_#{post.id}"
end
Expand Down

0 comments on commit 2150823

Please sign in to comment.