简体   繁体   English

rails precompile为什么javascript在本地不起作用,但在heroku它可以正常工作

[英]rails precompile Why javascript does not work locally but at heroku it works

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. 在部署到heroku时,我做了资产预编译然后部署,并且它在heroku上工作正常,但现在看来javascript被打破了。

Any suggestions on how to solve it? 有关如何解决的任何建议? Should I delete the files at public folder or use some configuration? 我应该删除公用文件夹中的文件还是使用某些配置?

Thanks in advance 提前致谢

UPDATE UPDATE

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)

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. 我正在使用twitter bootstrap,现在测试javascript是否搞砸了我添加了一个工具提示html示例来检查它是否也崩溃了,它确实有效。

But my dropdown at menu bar does not work. 但我在菜单栏上的下拉列表不起作用。 How strange is this? 这有多奇怪?

Finally I solved the problem. 最后我解决了这个问题。

Just changed in config/environments/development.rb 刚刚在config/environments/development.rb更改

config.assets.debug = true

to

config.assets.debug = false

And now javascript works as expected 现在javascript按预期工作

UPDATE UPDATE

Now when I have this problem I actually run rake assets:clean and clean the browser cache. 现在当我遇到这个问题时,我实际上运行了rake assets:clean并清理浏览器缓存。 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. 如果您希望拥有更好的流程,则可以创建一个新分支,在该分支中运行预编译并保持主分支清洁。

Other alternative is to run precompile on heroku so you don't have to do it locally. 其他替代方法是在heroku上运行预编译,这样您就不必在本地执行。 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 你可以在这里阅读它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JavaScript未在Heroku上加载,但可在本地使用 - JavaScript not loading on Heroku but works locally rails在本地工作,但是heroku上的服务器statut 304 - rails works locally, but server statut 304 on heroku Javascript可在本地使用,无法在网络服务器上使用 - Javascript works locally, will not work on webserver Rails:CSS / Javascript在本地运行良好,但在Heroku上却无法运行 - Rails : CSS/Javascript working fine locally but not on Heroku 为什么我的上传代码在本地工作,但在上传到 heroku 后不起作用? - Why is my code to upload working locally but does not work after being uploaded to heroku? Javascript不能在Heroku上工作但在本地工作,我该如何解决? - Javascript is not working on Heroku but works locally, how do I solve this? Javascript部署到Heroku时未执行,但在本地运行良好 - Javascript not executing when deployed to heroku, but works fine locally 我的JavaScript在本地可以运行,但是不能在服务器上运行吗? - my javascript works locally but not on the server why? 为什么javascript在我的网站上有效,而不在本地 - why javascript works on my website, but not locally Rails 4 - javascript文件未在生产中加载但在本地运行良好。 (Heroku的) - Rails 4 - javascript files not loading in production but working well locally. (Heroku)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM