如何在 Heroku 上使用 Sprockets Rails 插件?
我刚刚将 Rails 应用程序部署到 Heroku,但使用 Sprockets 插件的 Javascript 不起作用。
我明白,因为我的 Heroku 应用程序是只读的,Sprockets 无法工作。我发现这个 sprockets_on_heroku 插件应该可以完成这项工作,但我真的不知道如何使用它:
- 我在 config/environment.rb 中添加了
config.gem sprockets
- 我在 .gems 文件中添加了
sprockets
- 我将它们推送到了 Heroku 上,并且 Sprockets 已成功安装
- 我在本地运行
script/plugin install git://github.com/jeffrydegrande/sprockets_on_heroku.git
并且插件已成功安装
Heroku 上没有任何变化,所以我尝试使用 heroku 插件在 Heroku 上安装插件:install git://github.com/jeffrydegrande/sprockets_on_heroku.git
,它返回 sprockets_on_herokuinstalled
,但是随后,heroku restart
或 heroku plugins
命令将返回:
~/.heroku/plugins/sprockets_on_heroku/init.rb:1:未初始化的常量 ActionController (NameError)
来自 /opt/local/lib/ruby/gems/1.8/gems/heroku-1.8.3/bin/../lib/heroku/plugin.rb:25:in `load'
来自 /opt/local/lib/ruby/gems/1.8/gems/heroku-1.8.3/bin/../lib/heroku/plugin.rb:25:in `load!'
来自 /opt/local/lib/ruby/gems/1.8/gems/heroku-1.8.3/bin/../lib/heroku/plugin.rb:22:in `each'
来自 /opt/local/lib/ruby/gems/1.8/gems/heroku-1.8.3/bin/../lib/heroku/plugin.rb:22:in `load!'
来自 /opt/local/lib/ruby/gems/1.8/gems/heroku-1.8.3/bin/../lib/heroku/command.rb:14:in `run'
来自 /opt/local/lib/ruby/gems/1.8/gems/heroku-1.8.3/bin/heroku:14
来自 /opt/local/bin/heroku:19:in `load'
来自 /opt/local/bin/heroku:19
我应该做什么?
凯文
I just deployed my Rails app to Heroku, but the Javascripts that were using Sprockets plugin don't work.
I understood that, because my Heroku app is read-only, Sprockets won't work. I've found this sprockets_on_heroku plugin that should do the work, but I don't really get how to use it :
- I added
config.gem sprockets
in config/environment.rb - I added
sprockets
in my .gems file - I pushed these on Heroku and Sprockets was successfully installed
- I locally ran
script/plugin install git://github.com/jeffrydegrande/sprockets_on_heroku.git
and the plugin was successfully installed
Nothing changed on Heroku, so I tried to install the plugin on Heroku with heroku plugins:install git://github.com/jeffrydegrande/sprockets_on_heroku.git
, which returned sprockets_on_heroku installed
but then, a heroku restart
or a heroku plugins
command would return this:
~/.heroku/plugins/sprockets_on_heroku/init.rb:1: uninitialized constant ActionController (NameError)
from /opt/local/lib/ruby/gems/1.8/gems/heroku-1.8.3/bin/../lib/heroku/plugin.rb:25:in `load'
from /opt/local/lib/ruby/gems/1.8/gems/heroku-1.8.3/bin/../lib/heroku/plugin.rb:25:in `load!'
from /opt/local/lib/ruby/gems/1.8/gems/heroku-1.8.3/bin/../lib/heroku/plugin.rb:22:in `each'
from /opt/local/lib/ruby/gems/1.8/gems/heroku-1.8.3/bin/../lib/heroku/plugin.rb:22:in `load!'
from /opt/local/lib/ruby/gems/1.8/gems/heroku-1.8.3/bin/../lib/heroku/command.rb:14:in `run'
from /opt/local/lib/ruby/gems/1.8/gems/heroku-1.8.3/bin/heroku:14
from /opt/local/bin/heroku:19:in `load'
from /opt/local/bin/heroku:19
What should I do?
Kevin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

Sprockets on Heroku 的作者 Jeffry Degrande 回复了我的电子邮件。我唯一应该做的就是安装插件后
git push heroku
,以便将文件部署到 Heroku。简而言之:config.gem sprockets
sprockets
script/plugin install git://github.com/ jeffrydegrande/sprockets_on_heroku.git
Sprockets on Heroku's author Jeffry Degrande answered my e-mail. The only thing I should have done is to
git push heroku
after installing the plugin so that the files are deployed to Heroku. In short:config.gem sprockets
in config/environment.rbsprockets
in .gems filescript/plugin install git://github.com/jeffrydegrande/sprockets_on_heroku.git