javascript 未在带有rails 3.1 的heroku 上运行

发布于 2024-12-05 20:10:48 字数 1071 浏览 1 评论 0原文

我已将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

池予 2024-12-12 20:10:48

打开您的 application.rb 文件并确保您的 Bundler require 语句如下所示:

Bundler.require *Rails.groups(:assets)

默认情况下,它看起来像

# If you precompile assets before deploying to production, use this line
Bundler.require *Rails.groups(:assets => %w(development test))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)

Open your application.rb file and make sure your Bundler require statement looks like the following:

Bundler.require *Rails.groups(:assets)

By default it looks like

# If you precompile assets before deploying to production, use this line
Bundler.require *Rails.groups(:assets => %w(development test))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
遥远的她 2024-12-12 20:10:48

手动预编译对我有用。

bundle exec rake assets:precompile 在推送到 heroku 之前。

Manually precompiling worked for me.

bundle exec rake assets:precompile before you push to heroku.

金兰素衣 2024-12-12 20:10:48

您确定将 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

韶华倾负 2024-12-12 20:10:48

我遇到了一些 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.

可可 2024-12-12 20:10:48

我希望您在最新的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文