rails 预编译为什么 javascript 在本地不起作用,但在 heroku 上它起作用 [英] rails precompile Why javascript does not work locally but at heroku it works

查看:36
本文介绍了rails 预编译为什么 javascript 在本地不起作用,但在 heroku 上它起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在我预编译资产之前,该应用程序在本地运行良好.部署到 heroku 时,我进行了资产预编译,然后进行了部署,它在 heroku 上运行良好,但现在看来 javascript 已损坏.

So, the app was working great locally until I precompiled the assets. When deploying to heroku I did assets precompile and then deployed and it worked fine at heroku, but now it seems javascript got broken.

关于如何解决它的任何建议?我应该删除公共文件夹中的文件还是使用一些配置?

Any suggestions on how to solve it? Should I delete the files at public folder or use some configuration?

提前致谢

更新

我在开发模式下加载的每个资产文件都会得到一个,这正常吗?

I get one of this for each asset file I load in development mode, is it normal?

Started GET "/assets/home.js?body=1" for 127.0.0.1 at 2012-06-15 19:16:48 +0100
Served asset /home.js - 304 Not Modified (0ms)

这很奇怪.我正在使用 twitter bootstrap,现在为了测试 javascript 是否被搞砸了,我添加了一个工具提示 html 示例来检查它是否也崩溃了并且它确实有效.

This is odd. I'm using twitter bootstrap and now to test if javascript is messed up I added a tooltip html example to check if it is also crashed and it actually worked.

但是我在菜单栏中的下拉菜单不起作用.这有多奇怪?

But my dropdown at menu bar does not work. How strange is this?

推荐答案

我终于解决了这个问题.

Finally I solved the problem.

刚刚在 config/environments/development.rb

config.assets.debug = true

config.assets.debug = false

现在javascript按预期工作

And now javascript works as expected

现在当我遇到这个问题时,我实际上运行 rake assets:clean 并清理浏览器缓存.这将使您的应用像过去在开发工作中一样工作.

Now when I have this problem I actually run rake assets:clean and clean the browser cache. This will make your app work as it used to work in development work.

如果你想有一个更好的过程,你可以创建一个新的分支,在那里你运行预编译并保持你的主分支干净.

If you want to have a better process, you could instead create a new branch where you run precompile and keep your master branch clean.

其他替代方法是在 heroku 上运行预编译,这样您就不必在本地进行.我还没有尝试过,但您必须启用一个测试版"功能,这样它才能在所有应用程序中正常工作.你可以在这里

Other alternative is to run precompile on heroku so you don't have to do it locally. I haven't tried it yet but there is a 'beta' feature you have to enable so this can work properly in all apps. You can read about it here

这篇关于rails 预编译为什么 javascript 在本地不起作用,但在 heroku 上它起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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