Home Ruby 如何require一个文件(rails.root不好使。file.dirname(__file__)好使)
Post
Cancel

Ruby 如何require一个文件(rails.root不好使。file.dirname(__file__)好使)

呃。。。算了,这个语法问题,我不想知道为什么。能用就行了。

代码这样写不行,会报错:

require File.expand_path(Rails.root + "/lib/api_client.rb")
这样写就可以了:

require File.expand_path(File.dirname(__FILE__) + "/../lib/api_client.rb")

基础架构的搭建交给别人,我只负责用。。。。记录下来。  @.@

This post is licensed under CC BY 4.0 by the author.