I developed a Rails 3.1 application that consists of a 100% Ajax CRUD forms to input users and customers. I created two separate models, controllers, views etc. The views for each model contain jquery files for create edit update and destroy. The problem is when I perform any operation that performs a remote operation, it is called twice. I can confirm this happening in console view in firebug as well as output in WEBrick output. Can anyone assist in tracking down what happened here? What would cause rails to process each call twice?
Asked
Active
Viewed 7,257 times
13
-
some code will help to better understand the perspective ... e.g. post the code that is being called twice – Rafay Oct 11 '11 at 04:57
-
This is a hunch - is your JavaScript code or [`jquery-rails`](https://github.com/rails/jquery-rails) being included in the page twice? Check the public/assets folder if you have done any precompilation. – Anurag Oct 11 '11 at 05:01
-
@Anurag That's what I believe is happening. I ran "bundle exec rake assets:precompile" before this started happening. Do I just need to remove that file? – ctilley79 Oct 11 '11 at 05:06
-
You should only precompile for production. If you're in development mode, then remove everything from public/assets. I've faced the same problem a bunch of times in my current project, which I learnt the hard way :) – Anurag Oct 11 '11 at 05:08
-
@Anurag Thanks!!! You are a deity! – ctilley79 Oct 11 '11 at 05:13
-
Awesome. I'm feeling point-hungry today :), lemme post this as an answer. – Anurag Oct 11 '11 at 05:24
2 Answers
19
Adding config.serve_static_assets = false
to development.rb
will prevent loading files from /public/assets
.
Actually I need to precompile locally because my test mode is using only static assets from /public/assets
- tests are catching possible production asset problems. How? Just set config.assets.compile = false
and config.serve_static_assets = true
in test.rb
configuration.

gertas
- 16,869
- 1
- 76
- 58
-
1From Rails 4 onwards, `config.serve_static_assets` is deprecated. Use `config.serve_static_files` instead. – Jin Aug 18 '15 at 13:25
13
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.

Anurag
- 140,337
- 36
- 221
- 257
-
I tried to follow your solution (that is, to delete the public/assets path at all and restart my server) but I am still getting the problem explained in the question. Am I forgetting to do something? – user12882 Nov 03 '11 at 17:42
-
2It's a caching issue. reset your browser cache. Happened to me before I figured it out – ctilley79 Nov 08 '11 at 20:51
-
2Did you know that there is a rake command to do that? Just write: rake assets:clean in your terminal. ;) – Kulgar Jul 17 '12 at 13:27