Ruby on Rails 3.1 - Assets Pipeline - Assets Rendered Twice

Ruby On Rails 3.1 - assets pipeline - assets rendered twice

You might want to look at

https://stackoverflow.com/a/7854902/686460

"Adding config.serve_static_assets = false to development.rb will prevent loading files from /public/assets"

I think that is a better solution than what you are suggesting here.

Why does Rails duplicate assets when using yield?

shouldn't Rails guarantee that no duplicate files are rendered? Can I
still keep the "redundant" dependencies and have the files rendered
only once?

simple answer: no

assets are precompiled and so "static" in production. you may include assets in several ways. so there is no way for rails to "know" what files should be eliminated in the context of your rendered page.

YOU need to make sure there are not duplicates.

Rails 3.1 remote requests submitting twice

If you have precompiled the assets and running in development mode, then the JavaScripts will be included twice on the page.

Remove everything from public/assets if in development mode.

Rails 3.1 with Asset Pipeline, link_to :confirm message showing twice?

This has happened to me because I had run rake assets:precompile in my development environment causing public/assets/application.js to be created. This makes requests for /assets/application.js to be served by this static file which contains all // require scripts in public/assets/application.js compiled together, causing them to be loaded once again.

In development mode <%= javascript_include_tag "application" %> will expand in to multiple <script> tags, one for each file required by // require lines, and also one for application.js which only contain its own content.

Solution is to remove the whole public/assets directory manually or use the assets:clean rake task. This will cause scripts files to be served dynamically again.

Why do I have to deploy twice for changes in asset pipeline to be picked up?

Okay, I figured out how to get it working, but it isn't clean. For some reason, deploy:assets:precompile is being run just before deploy:create_symlink, rather than after. The result is that the current directory on the server is not yet pointing at the new code when assets are being compiled, so they're only compiling for the previous deploy. This is why my assets were not updating unless I deployed twice.

I applied a quick-fix by adding this:

before "deploy:assets:precompile", "deploy:create_symlink"

This triggers the creating the symlink just before precompiling so that asset changes are picked up. The result is that the symlink is created twice, because the existing behavior is also still run. It works, but it feels dirty.

I'm really not sure why this is an issue in the first place, and I don't understand why nobody else seems to be having this issue; my deploy.rb is pretty cut-and-dry, nothing too fancy going on. The only thing I can think of is that load "deploy/assets" isn't in the right place in the file. I just assumed it went at the top, and I don't know if it affects the order of execution.

Any suggestions as the the correct way to fix this would be greatly appreciated!

javascript included twice in a Rails 3.1 asset-based app

It turns out that the culprit was the rails-widgets plugin, and in particular this bit of code, part of the widgets' initialization.

After removing it, all went back to normal. Javascript assets are now loaded once as expected, in both development and production.

While I apologize for not finding out sooner that the problem was quite specific to my setup, I still hope that the solution may serve some purpose. Thank you all.

Giuseppe

Rails 3.1 Assets - Strange Serving in Development

Try adding the following to development.rb:

config.serve_static_assets = false

...and then clearing your browser cache (update based on comments)

The static assets refer to precompiled assets in public/assets, which is where rake assets:precompile puts them.

What's happening is that anything that exists in public/assets will override anything in app/assets if you are serving them. So public/assets/application.js is being loaded when the js tag is intending to identifiy app/assets/application.js.

Rails 3.1 assets pipeline and page refreshing

Ok, the problem was in permissions to tmp folder



Related Topics



Leave a reply



Submit