Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paper_trail gem: uninitialized constant VersionsController::Version

I had this working fine following the Railscast episode by Ryan Bates and then some weeks later I went back to check on it and it was borked. Now I'm getting this error whenever I hit the undo button:

uninitialized constant VersionsController::Version

I have it set up exactly as in the screencast, but I have no clue what might have broken it.

Problem is on line 3 apparently:

class VersionsController < ApplicationController
  def revert
    @version = Version.find(params[:id])
    @version.reify.save!
    redirect_to :back, :notice => "Undid #{@version.event}"
  end
end

Any suggestions?

http://railscasts.com/episodes/255-undo-with-paper-trail

like image 568
John Trichereau Avatar asked Nov 18 '13 11:11

John Trichereau


1 Answers

The latest versions of Papertrail actually namespace the Version class as PaperTrail::Version. This will fix the problem immediately.

Here is an example:

def revert
  @version = PaperTrail::Version.find(params[:id])
  if @version.reify
    @version.reify.save!
  else
    @version.item.destroy
  end
end
like image 53
John Trichereau Avatar answered Nov 09 '22 22:11

John Trichereau