Using paper_trail to combine act_as_taggable_on associations
I am working on a bug on a rails engine using both paper_trail and act_as_taggable_on. When I roll back a deleted event, the event information is restored but the tags are missing. Has anyone faced this problem?
Some relevant information:
models / calagaor / event.rb
class Event < ActiveRecord::Base
has_paper_trail
acts_as_taggable
end
I also created config / initializers / act_as_taggable.rb file:
ActsAsTaggableOn::Tag.class_eval do
has_paper_trail
end
ActsAsTaggableOn::Tagging.class_eval do
has_paper_trail
end
I am new to rails, so not sure if I will go back in the right direction or not. Let me know if you need more details. Thank!
Edit:
Controllers / calagator / versions_controller.rb
module Calagator
class VersionsController < Calagator::ApplicationController
def edit
@version = PaperTrail::Version.find(params[:id])
@record = @version.next.try(:reify) || @version.item || @version.reify
singular = @record.class.name.singularize.underscore.split("/").last
plural = @record.class.name.pluralize.underscore.split("/").last
self.instance_variable_set("@#{singular}", @record)
if request.xhr?
render :partial => "calagator/#{plural}/form", :locals => { singular.to_sym => @record }
else
render "calagator/#{plural}/edit", :locals => { singular.to_sym => @record }
end
end
end
end
I am using paper_trail '3.0.8'
+3
source to share