简体   繁体   English

从4.0.2升级到4.2.0会破坏paper_trail代码

[英]Upgrading from 4.0.2 to 4.2.0 breaks paper_trail code

I am getting the following error in 4.2.0 which works in 4.0.2: 我在4.2.0中遇到以下错误,该错误在4.0.2中有效:

undefined method `reverse!' 未定义的方法“反向!” for # 对于#

in the following line of code: 在下面的代码行中:

 def show
    @client     = Client.find(params[:id])
    @versions   = @client.versions.reverse!   <-- error line
  end

typing in @client.versions.class yields the following: 输入@ client.versions.class会产生以下结果:

>> @client.versions.class
=> PaperTrail::Version::ActiveRecord_Associations_CollectionProxy
>>

Any idea anyone? 有人知道吗?

Thanks. 谢谢。

You shouldn't even be trying to use the destructive reverse! 您甚至都不应该尝试使用破坏性的reverse! method, that (if it worked) alters the array it's being called on. 方法,(如果它起作用的话)改变被调用的数组。 Thankfully that's been removed from the underlying classes. 幸运的是,这已从基础类中删除。 Instead you should just use reverse which still returns a reversed array, but doesn't alter the array it's being called on. 取而代之的是,您应该只使用reverse ,它仍会返回一个反向数组,但不会更改正在调用的数组。

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

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