13

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?

6
  • some code will help to better understand the perspective ... e.g. post the code that is being called twice Commented Oct 11, 2011 at 4:57
  • This is a hunch - is your JavaScript code or jquery-rails being included in the page twice? Check the public/assets folder if you have done any precompilation. Commented Oct 11, 2011 at 5: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? Commented Oct 11, 2011 at 5: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 :) Commented Oct 11, 2011 at 5:08
  • @Anurag Thanks!!! You are a deity! Commented Oct 11, 2011 at 5:13

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

From Rails 4 onwards, config.serve_static_assets is deprecated. Use config.serve_static_files instead.
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.

3 Comments

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?
It's a caching issue. reset your browser cache. Happened to me before I figured it out
Did you know that there is a rake command to do that? Just write: rake assets:clean in your terminal. ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.