forum previews working

This commit is contained in:
albert
2011-03-12 16:09:11 -05:00
parent 21cc1cbafa
commit bd520f61f7
29 changed files with 1516 additions and 81 deletions

View File

@@ -6,6 +6,7 @@ class ForumPost < ActiveRecord::Base
before_validation :initialize_updater
after_save :update_topic_updated_at
validates_presence_of :body, :creator_id
validate :validate_topic_is_unlocked
scope :body_matches, lambda {|body| where(["text_index @@ plainto_tsquery(?)", body])}
search_method :body_matches
@@ -19,6 +20,18 @@ class ForumPost < ActiveRecord::Base
new
end
end
def validate_topic_is_unlocked
return if CurrentUser.is_moderator?
return if topic.nil?
if topic.is_locked?
errors.add(:topic, "is locked")
return false
else
return true
end
end
def editable_by?(user)
creator_id == user.id || user.is_moderator?

View File

@@ -7,6 +7,7 @@ class ForumTopic < ActiveRecord::Base
before_validation :initialize_creator, :on => :create
before_validation :initialize_updater
validates_presence_of :title, :creator_id
validates_associated :original_post
scope :title_matches, lambda {|title| where(["text_index @@ plainto_tsquery(?)", title])}
search_methods :title_matches
accepts_nested_attributes_for :original_post