I am new to Ruby and Rails and am having trouble getting a class in /lib to reference another class in /lib.
I have this in my application.rb file, as I understand Rails 3 does not auto-load the lib directory:
config.autoload_paths += %W(#{config.root}/lib)
Then I have lib/Rec.rb
class Rec
Movie @movie
...
and then lib/Movie.rb. I am able to instantiate a Movie object in a controller, but referencing in Rec produces:
undefined method `Movie' for Rec:Class
...
lib/rec.rb:2:in `<class:Rec>'
lib/rec.rb:1:in `<top (required)>'
Your code is…messed up. What do you mean
Movie @movie? What exactly do you want to do?That piece of code is invalid Ruby unless you have declared
Movieas a method somewhere. But Movie should be a class, right? So that’s the first reason Rails is not loading yourmovie.rbfile, because Ruby is confused about what your code means.Maybe what you mean is
Something like that should autoload your
movie.rb, because now the code makes sense.But..
..doesn’t mean anything..