3

I'm working in a new rails app and I created a little utility class in RAILS_ROOT/lib. I use this class in one of the controller with a require. In local this class is correctly loaded but when I deploy the app on heroku it crashes with:

LoadError (no such file to load -- MyUtilityClass)

Any ideas?

UPDATE:

I found the problem. In my controller I did a 'require "MyUtilityClas" ' and that was working fine locally. On heroku I needed to do a 'require "/lib/my_utility_class.rb" '. Hmmm... I do not really understand why in fact...

Luc
  • 16,604
  • 34
  • 121
  • 183
  • What is the full name of the file? is it /lib/my_utility_class.rb ? – Jesse Wolgamott Mar 29 '11 at 20:24
  • `lib` should still be on the load path in heroku I think... does your file `my_utility_class.rb` define a `MyUtilityClass` constant? Rails should pick that up automagically if it does so you shouldn't have to required it manually. – brad Mar 29 '11 at 20:58
  • 1
    5 years later this is still not consistent with my local environment. I found that using `require "/lib/my_class.rb"` did not work locally, but doing `require "my_class.rb"` did work for me locally and on heroku. I just had to add the `.rb` ending. – Danny Dec 03 '16 at 23:10

3 Answers3

6

you want require 'my_file_to_require' assuming you've named your file properly.

Require takes the filename, not the module/class name, so:

require 'MyUtilityClass'   # wrong

is wrong but

require 'my_utility_class'  # correct

is correct, again assuming you've stuck to the normal ruby/rails file naming conventions.

brad
  • 31,987
  • 28
  • 102
  • 155
1

Have you checked the Heroku logs?!

Tim
  • 531
  • 2
  • 7
  • 25
  • in the log, I just have the error message: LoadError (no such file to load -- MyUtilityClass) – Luc Mar 29 '11 at 19:37
1

Have you tried to restart your app after it's deployed? You can use the following command:

heroku restart
Pierre
  • 8,368
  • 4
  • 34
  • 50