javascript 未在带有rails 3.1 的heroku 上运行
我已将 Heroku 上的 Rails 3.0 应用程序迁移到 3.1。它在 cedar 堆栈上运行,除了应用程序的 javascript 无法运行之外,一切都很好。 application.js 文件已编译并且看起来如其应有的样子。可以通过访问 myapp.com/assets/application.js 进行访问。它只是没有运行!
如果我在本地运行该应用程序,则 JavaScript 可以正常工作,因此我怀疑一定存在一些我遗漏的简单配置问题。这是我的 production.rb 文件:
FloridaBirdTrail::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
end
编辑
将 production.rb 的内容替换为development.rb 的内容至少允许我的部分 javascript 运行(由于某种原因,gmap3 无法工作)。但哪个设置会产生影响呢?
I've migrated a rails 3.0 app to 3.1 on Heroku. It's running on the cedar stack and everything is fine except that the app's javascript won't run. The application.js file is compiled and looks just as it should. It's accessible by going to myapp.com/assets/application.js. It just doesn't get run!
If I run the app locally, the javascript works, so I suspect that there must be some simple configuration issue that I'm missing. Here's my production.rb file:
FloridaBirdTrail::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
end
edit
Replacing the contents of production.rb with that of development.rb has allowed at least some of my javascript to run (gmap3 isn't working, for some reason). But which of the settings is making the difference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
打开您的
application.rb
文件并确保您的Bundler
require 语句如下所示:默认情况下,它看起来像
Open your
application.rb
file and make sure yourBundler
require statement looks like the following:By default it looks like
手动预编译对我有用。
bundle exec rake assets:precompile
在推送到 heroku 之前。Manually precompiling worked for me.
bundle exec rake assets:precompile
before you push to heroku.您确定将 Heroku 切换到 Cedar 堆栈吗?以下是一些升级文档
http://devcenter.heroku.com/articles/rails31_heroku_cedar#upgrading_from_previous_rails_31_releases
<一个href="http://devcenter.heroku.com/articles/cedar" rel="nofollow">http://devcenter.heroku.com/articles/cedar
Were you sure to switch Heroku to the Cedar stack? Here are some docs for upgrading
http://devcenter.heroku.com/articles/rails31_heroku_cedar#upgrading_from_previous_rails_31_releases
http://devcenter.heroku.com/articles/cedar
我遇到了一些 Javascript 问题(Heroku 上的服务器端,本地一切都很好),当我
* 将我所有的 Javascript 移到一个单独的文件中,而不是 application.js
* 从 application.js 中删除了 require_tree ,而是通过名称调用了我想要的每个 javascript
* 从我的 app/assets/javascript 文件夹中删除了 bootstrap.js
我的猜测是编译不知何故把事情搞砸了。
I had some Javascript problems (server-side on Heroku, locally everything was fine) that went away when I
* moved all my Javascript into a separate file instead of application.js
* removed require_tree from application.js and instead called up every javascript I wanted by name
* removed bootstrap.js from my app/assets/javascript folder
My guess is that compilation somehow screws things up.
我希望您在最新的 Heroku 推送之前对资产进行了本地预编译(如上述回复之一所建议)。
请检查您的系统是否阻止 JavaScript 的执行。为此,请在使用 Heroku 应用程序时打开控制台,并检查是否有异常。如果您看到与 JavaScript 被阻止相关的异常,这可能就是问题所在。就我而言,同样的事情发生了,不幸的是,我无法对此做任何事情,因为我没有管理员权限。
I hope you did a local pre-compilation of assets before your latest Heroku push (as advised in one of the responses above).
Please check if your system is blocking the execution of JavaScripts. For this, open up the console while you are on your Heroku app, and check for exceptions. In case you see exceptions related to JavaScripts being blocked, that could be the issue. In my case, the same happened, and unfortunately, I was not able to do anything about it, as I didn't have admin privileges.