简体   繁体   English

使用paper_trail来重新定义acts_as_taggable_on关联

[英]Using paper_trail to reify acts_as_taggable_on associations

I'm working on a bug on a rails engine using both paper_trail and acts_as_taggable_on. 我正在使用paper_trail和acts_as_taggable_on处理rails引擎上的错误。 When I rollback a deleted event the event details are restored, but the tags are not. 当我回滚已删除的事件时,将恢复事件详细信息,但不会恢复标记。 Has anyone came across this same issue? 有人遇到过同样的问题吗?

Some relevant info: 一些相关信息:

models/calagaor/event.rb 车型/ calagaor / event.rb

class Event < ActiveRecord::Base
  has_paper_trail
  acts_as_taggable 
end

I also created a config/initializers/act_as_taggable.rb file: 我还创建了一个config / initializers / act_as_taggable.rb文件:

ActsAsTaggableOn::Tag.class_eval do
  has_paper_trail
end

ActsAsTaggableOn::Tagging.class_eval do
  has_paper_trail
end 

I'm pretty new to rails so I'm not sure if I'm headed in the right direction or not. 我对铁轨很陌生,所以我不确定自己是否朝着正确的方向前进。 Let me know if you need more details. 如果您需要更多详细信息,请告诉我们。 Thanks! 谢谢!

Edit: 编辑:

controllers/calagator/versions_controller.rb 控制器/ 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'm using paper_trail '3.0.8' 我正在使用paper_trail'3.0.8'

[How do I use] paper_trail to reify acts_as_taggable_on associations? [我如何使用] paper_trail来实现acts_as_taggable_on关联? I'm using paper_trail '3.0.8' 我正在使用paper_trail'3.0.8'

paper_trail 3 doesn't do associations. paper_trail 3不做关联。 Try upgrading to paper_trail 4. 尝试升级到paper_trail 4。

Docs: https://github.com/airblade/paper_trail#associations 文档: https//github.com/airblade/paper_trail#associations

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM