开发者

No such file to load, Model/Lib naming conflict?

开发者 https://www.devze.com 2022-12-29 21:09 出处:网络
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).

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 defin开发者_C百科itely 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.


Try using the full path:

require File.join(RAILS_ROOT, 'lib', 'Animals', 'Dog.rb')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号