[英]RoR app works fine locally, but errors when using a from /lib when run on Heroku
My RoR app works fine when run locally, but when I run it on Heroku, it errors on this line: 我的RoR应用程序在本地运行时运行良好,但是当我在Heroku上运行时,此行出错:
my_reader = Docreader.new(params[:doc])
Error: 错误:
NameError (uninitialized constant NotesController::Docreader):
Docreader.rb is located in the lib folder Docreader.rb位于lib文件夹中
I've tried heroku restart
, but it didn't help. 我尝试了
heroku restart
,但是没有帮助。 What am I doing wrong? 我究竟做错了什么? Thanks for reading.
谢谢阅读。
The likely culprit is the uppercase letter D
in Docreader.rb
. 可能的罪魁祸首是
Docreader.rb
的大写字母D
You need to make sure it is named docreader.rb
- in all lower-case letters. 您需要确保将其命名为
docreader.rb
所有小写字母。 Heroku uses a case-sensitive file system, so a mixed case file will work locally in OS X or Windows, but not on Heroku. Heroku使用区分大小写的文件系统,因此混合大小写的文件将在OS X或Windows本地运行,但在Heroku上不行。
In general, it is not advised to use any upper-case letters in your filenames with Ruby on Rails (and lowercase is also the de-facto standard in Ruby), as Rails's auto-loading code always uses lowercase. 通常,不建议在Ruby on Rails的文件名中使用任何大写字母(并且小写也是Ruby中的事实上的标准),因为Rails的自动加载代码始终使用小写。
I had a similar problem with getting my module to run on Heroku. 让我的模块在Heroku上运行时,我遇到了类似的问题。 In addition to the autoload naming convention stated by @wuputah, I found out that the module code must be required due to a threadsafe assumption made by the Rails' production environment on Heroku (even though it was commented out in my production.rb file.) As soon as I "required" the module file before calling "include" on the module, everything started to work.
除了@wuputah声明的自动加载命名约定外,我发现由于Rails在Heroku的生产环境中做出的线程安全假设,还必须使用模块代码(即使在我的production.rb文件中已将其注释掉)。 )在模块上调用“ include”之前,一旦我“需要”模块文件,一切就开始起作用。
Please take a look at this excellent article on the subject of getting Modules to load correctly in Heroku: 请看这篇关于如何在Heroku中正确加载模块的优秀文章:
http://www.williambharding.com/blog/technology/rails-3-autoload-modules-and-classes-in-production / http://www.williambharding.com/blog/technology/rails-3-autoload-modules-and-classes-in-production/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.