add options for modifying commentary/commentary_request tags on form #2623

This commit is contained in:
r888888888
2016-07-19 16:49:04 -07:00
parent 37bc7279e3
commit 35a6f60dc4
4 changed files with 68 additions and 3 deletions

View File

@@ -1,9 +1,12 @@
class ArtistCommentary < ActiveRecord::Base
attr_accessible :post_id, :original_description, :original_title, :translated_description, :translated_title
attr_accessor :remove_commentary_tag, :remove_commentary_request_tag
attr_accessor :add_commentary_tag, :add_commentary_request_tag
attr_accessible :post_id, :original_description, :original_title, :translated_description, :translated_title, :remove_commentary_tag, :remove_commentary_request_tag, :add_commentary_tag, :add_commentary_request_tag
validates_uniqueness_of :post_id
belongs_to :post
has_many :versions, lambda {order("artist_commentary_versions.id ASC")}, :class_name => "ArtistCommentaryVersion", :dependent => :destroy, :foreign_key => :post_id, :primary_key => :post_id
after_save :create_version
after_commit :tag_post
module SearchMethods
def text_matches(query)
@@ -83,4 +86,24 @@ class ArtistCommentary < ActiveRecord::Base
revert_to(version)
save!
end
def tag_post
if remove_commentary_tag == "1"
post.remove_tag("commentary")
end
if add_commentary_tag == "1"
post.add_tag("commentary")
end
if remove_commentary_request_tag == "1"
post.remove_tag("commentary_request")
end
if add_commentary_request_tag == "1"
post.add_tag("commentary_request")
end
post.save if post.tag_string_changed?
end
end

View File

@@ -754,6 +754,14 @@ class Post < ActiveRecord::Base
!!(tag_string =~ /(?:^| )(?:#{tag})(?:$| )/)
end
def add_tag(tag)
set_tag_string("#{tag_string} #{tag}")
end
def remove_tag(tag)
set_tag_string((tag_array - tag).join(" "))
end
def has_dup_tag?
has_tag?("duplicate")
end