Rails,Heroku不加载我的lib [英] Rails, Heroku does not load my lib

查看:79
本文介绍了Rails,Heroku不加载我的lib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个新的rails应用程序中工作,并在 RAILS_ROOT / lib 中创建了一个小实用程序类。我在 require >的控制器之一中使用这个类。在本地这个类是正确加载,但是当我在heroku上部署应用程序时,它会崩溃:


LoadError(no file to load - MyUtilityClass)

任何想法?



更新:



我发现了这个问题。在我的控制器中,我做了一个需要MyUtilityClas',并且在本地工作正常。在heroku上,我需要做一个'require'/lib/my_utility_class.rb''。嗯...我真的不明白为什么... ...

解决方案

你想要 require' my_file_to_require'假设你正确地命名了你的文件。



Require需要文件名,而不是模块/类名,所以:

  require'MyUtilityClass'#wrong 

不正确,但

 需要'my_utility_class'#正确



是正确的,再次假设您坚持使用正常的ruby / rails文件命名约定。


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...

解决方案

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.

这篇关于Rails,Heroku不加载我的lib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆