ruby-on-rails - 删除关系未经过已审核 gem 的审核

标签 ruby-on-rails ruby ruby-on-rails-4 acts-as-audited

我正在使用Associated Audits与集体理念 auditedhas_many through 关系 gem 。我看到正在添加针对 through 模型的 create 审核,但删除该关系后我没有看到任何审核。

这是我的 3 个模型。一个帖子可以属于多个类别

app/models/post.rb

class Post < ActiveRecord::Base
  audited
  has_associated_audits

  has_many :categorizations, dependent: :destroy
  has_many :categories, through: :categorizations
end

app/models/category.rb

class Category < ActiveRecord::Base
  audited
  has_associated_audits

  has_many :categorizations, dependent: :destroy
  has_many :posts, through: :categorizations
end

app/models/categorization.rb

class Categorization < ActiveRecord::Base
  audited
  audited associated_with: :post
  audited associated_with: :category

  belongs_to :category
  belongs_to :post
end

我的Post表单有一堆用于分类的复选框:

<%= f.association :categories, as: :check_boxes, collection: Category.order(:name), label_method: :name, value_method: :id, label: false %>
  • 当我编辑现有帖子选中类别复选框时,我确实看到一个新的审核操作字段中带有 create 值的审核条目。
  • 当我编辑现有的帖子取消选中类别的复选框时,我没有看到新的审核条目。
  • 当我删除 Post< 时,我确实看到了 PostCategorizationauditable_type 字段的 destroy 审核,所以这方面工作得很好。

    1. 经过审计可以跟踪这些取消选择吗?如果是这样,怎么办?
    2. 我在上述模型中审核的设置是否有任何明显的错误/错误?没有可遵循的 has_many through 文档,所以我猜测了一下。

最佳答案

可能与this Rails issue相关,我不得不换掉我的dependent: :destroy行:

app/models/post.rb

class Post < ActiveRecord::Base
  audited
  has_associated_audits

  has_many :categorizations
  has_many :categories, through: :categorizations, dependent: :destroy
end

app/models/category.rb

class Category < ActiveRecord::Base
  audited
  has_associated_audits

  has_many :categorizations
  has_many :posts, through: :categorizations, dependent: :destroy
end

完成此设置后,我可以看到添加和删除关系的审核。

关于ruby-on-rails - 删除关系未经过已审核 gem 的审核,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34073757/

相关文章:

ruby-on-rails - 如何 stub after_create 回调保存!在模型中?

html - 在 Rails 网络应用程序中,单击链接后样式会发生细微变化

ruby-on-rails - Multi-Tenancy 应用程序的 rails 覆盖/范围 View

ruby-on-rails - 使用 Rails 4(和 Hstore)在 PostgreSQL 中存储嵌套哈希

mysql - 基于公共(public)属性的采摘(rails)

ruby-on-rails - 从excel文件读取数据到postgres数据库(Active Record)

ruby-on-rails - 在 Rails 中使用 devise 时,如何添加将以两种不同方式使用该网站的两种不同类型的用户?

javascript - 一个 Rails View 上的多个 Ajax 请求

ruby-on-rails - 确保应用程序级别的唯一列值

ruby - 带 ActiveSupport 的默认时区(无 Rails)