简体   繁体   English

Paper Trail gem使名称版本的字段不可用

[英]Paper trail gem makes fields with the name version unusable

I have a table named clients backed by an AR model Client . 我有一个表名为clients通过AR模型支持的Client This is the structure of clients table: 这是clients表的结构:

clients
  - id <serial primary key>
  - name <varchar(255)>
  - version <varchar(255)>

I have added versioning to it using the paper trail gem. 我已经添加了使用Paper Trail gem的版本控制。 However, when I update or create the record, the column version does not update. 但是,当我更新或创建记录时,列version不会更新。 And when I do Client.first.version it gives me nil value even though all my records in the table have a version column that is not null or empty. 而且当我执行Client.first.version ,即使表中的所有记录的version列都不为null或为空,它Client.first.version nil值。 I suspect this is because of paper trail gem. 我怀疑这是因为有纸痕宝石。 When I switch my project's branch to a version that does not use the gem, I am able to get non-nil value of version. 当我将项目的分支切换到不使用gem的版本时,我能够获得非null版本的值。

Is there any workaround to fix this issue? 是否有解决此问题的解决方法?

Sure, there is. 当然可以。 Problem is, version is the default association name in paper_trail, thus calling the association on client rather than fetching it's attribute. 问题是, version paper_trail中的默认关联名称,因此在客户端上调用该关联,而不是获取其属性。 You can change your model as: 您可以将模型更改为:

class Client < ActiveRecord::Base
  has_paper_trail version: :paper_version, versions: :paper_versions
end

c = Client.first
c.version #=> row field
c.paper_versions #=> previous versions.

Edit: Just found that it is also documented in paper_trail here - https://github.com/airblade/paper_trail#6-extensibility 编辑:刚刚发现它也记录在paper_trail此处-https: //github.com/airblade/paper_trail#6-extensibility

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

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