Search code examples
ruby-on-railsupgradepaper-trail-gem

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:

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
=> PaperTrail::Version::ActiveRecord_Associations_CollectionProxy
>>

Any idea anyone?

Thanks.


Solution

  • You shouldn't even be trying to use the destructive 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.