forum previews working
This commit is contained in:
@@ -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?
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user