work on forum

This commit is contained in:
albert
2011-03-11 19:24:19 -05:00
parent 7dd345ca75
commit 21cc1cbafa
24 changed files with 343 additions and 1306 deletions

View File

@@ -8,6 +8,17 @@ class ForumPost < ActiveRecord::Base
validates_presence_of :body, :creator_id
scope :body_matches, lambda {|body| where(["text_index @@ plainto_tsquery(?)", body])}
search_method :body_matches
def self.new_reply(params)
if params[:topic_id]
new(:topic_id => params[:topic_id])
elsif params[:post_id]
forum_post = ForumPost.find(params[:post_id])
forum_post.build_response
else
new
end
end
def editable_by?(user)
creator_id == user.id || user.is_moderator?
@@ -25,4 +36,10 @@ class ForumPost < ActiveRecord::Base
def initialize_updater
self.updater_id = CurrentUser.id
end
def build_response
dup.tap do |x|
x.body = "[quote]\n#{x.body}\n[/quote]\n\n"
end
end
end

View File

@@ -22,4 +22,12 @@ class ForumTopic < ActiveRecord::Base
def initialize_updater
self.updater_id = CurrentUser.id
end
def last_page
(posts.count / Danbooru.config.posts_per_page.to_f).ceil
end
def presenter(forum_posts)
@presenter ||= ForumTopicPresenter.new(self, forum_posts)
end
end