最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

rails precompile Why javascript does not work locally but at heroku it works - Stack Overflow

programmeradmin0浏览0评论

So, the app was working great locally until I prepiled the assets. When deploying to heroku I did assets prepile 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?

Thanks in advance

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.

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

So, the app was working great locally until I prepiled the assets. When deploying to heroku I did assets prepile 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?

Thanks in advance

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.

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

Share Improve this question edited Nov 11, 2013 at 16:01 Ismael asked Jun 15, 2012 at 17:18 IsmaelIsmael 16.7k6 gold badges63 silver badges76 bronze badges 2
  • Have you tried running in the same environment (production, staging, etc...) locally as you're running on Heroku? – badams Commented Jun 15, 2012 at 17:40
  • I did now in production environment. It even can't load css. I don't know why. It says application-XXXXXXXXXXX.css cannot be found but it is at public/assets – Ismael Commented Jun 15, 2012 at 18:02
Add a ment  | 

1 Answer 1

Reset to default 11

Finally I solved the problem.

Just changed in config/environments/development.rb

config.assets.debug = true

to

config.assets.debug = false

And now javascript works as expected

UPDATE

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 prepile and keep your master branch clean.

Other alternative is to run prepile 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

发布评论

评论列表(0)

  1. 暂无评论