简体   繁体   English

RoR应用程序在本地运行良好,但是在Heroku上运行时使用来自/ lib的错误

[英]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.

相关问题 Heroku + RoR如何在本地运行应用程序 - Heroku +RoR how run app locally Rails应用程序在本地运行,但在部署到Heroku时则不行 - Rails app works locally but not when deployed to Heroku Rails App可在本地运行,但在Heroku上部署时无法运行 - Rails App works locally but not when deployed on Heroku 部署到Heroku时出现ActionView错误,在本地工作正常 - ActionView error when deploying to Heroku, works fine locally 在运行时在heroku中发送文本时,Rails Twilio App会挂起,但在heroku(以及所有环境中的本地)的Rail console中可以运行 - Rails Twilio App hangs when sending text in heroku on run, but works in rail console on heroku (and locally in all environments) 在heroku上部署Rails应用程序时遇到问题(该应用程序在本地运行良好)? - Having issues with deploying Rails app on heroku( app works fine locally)? Rails在本地工作正常,但在heroku中没有 - Rails works fine locally but not in heroku 控制器可以在本地正常运行,但不能在heroku上运行 - Controller works fine locally but not on heroku Rails应用程序可以在本地使用载波在S3上正常运行,在Heroku上崩溃,并显示错误消息“无法自动加载常量” - Rails app works fine with S3 using carrierwave locally, crashes on Heroku with error message 'Unable to autoload constant' Javascript资产未加载到已部署的Heroku应用(生产)中,但在本地运行良好 - Javascript assets not loading to deployed Heroku app(Production), but works fine locally
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM