Paper_trail gem: uninitialized constant VersionsController::Version
Asked Answered
M

1

7

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

Metronymic answered 18/11, 2013 at 11:10 Comment(5)
Did you put a has_paper_trail in your model?Esteban
Hi here's the answer to my own question: The latest versions of Papertrail actually namespace the Version class as PaperTrail::Version. Fixed the problem immediately.Metronymic
This was the second thing I would suggest you to do :). You should post your own answer and accept it for later visitors.Esteban
Can't my reputation is 1. Next time :)Metronymic
Now maybe you can add your answer?Ribeiro
M
8

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
Metronymic answered 19/1, 2014 at 1:23 Comment(2)
Hi, I'm running into the same problem, and unfortunately I don't understand what is meant by namespacing! Could you please post a sample code up to show what changes needs to be made? I'm sure it'll help other newbies like myself. Many thanks!Verine
See the example I added above.Metronymic

© 2022 - 2024 — McMap. All rights reserved.