My RoR app works fine when run locally, but when I run it on Heroku, it errors on this line:
my_reader = Docreader.new(params[:doc])
Error:
NameError (uninitialized constant NotesController::Docreader):
Docreader.rb is located in the lib folder
I've tried heroku restart
, but it didn't help. What am I doing wrong? Thanks for reading.
The likely culprit is the uppercase letter D
in Docreader.rb
. You need to make sure it is named docreader.rb
- in all lower-case letters. Heroku uses a case-sensitive file system, so a mixed case file will work locally in OS X or Windows, but not on 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.
I had a similar problem with getting my module to run on 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.
Please take a look at this excellent article on the subject of getting Modules to load correctly in Heroku:
http://www.williambharding.com/blog/technology/rails-3-autoload-modules-and-classes-in-production /
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.