Question

I'm working on a Rails application. I have a Module called Animals. Inside this Module is a Class with the same name as one of my Models (Dog).

show_animal action:


def show_animal
  require 'Animals/Bear.rb' #Works
  require 'Animals/Dog.rb' #Fails
end

So the first require definitely works, the seconds fails. MissingSourceFile (no such file to load -- Animals/Dog.rb):

I noticed that Dog.rb is the same file name as one of my models, is that what's causing this? I'm using Webrick.

Was it helpful?

Solution

Try using the full path:

require File.join(RAILS_ROOT, 'lib', 'Animals', 'Dog.rb')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top