2
<%=link_to 'Add note', {:controller => 'home', :action => 'add_note', :id =>user.id}, :remote => true%> 

After click on this link is called the page _add_note.html.erb (via JS add_note.js.erb). This file looks this:

$('div#ajax_div').html("<%= escape_javascript(render('add_note')) %>"); 

It looks good, after click on the link above is loaded to the ajax_div a content of the file _add_note.html.erb.

But the problem is, that after click on the link I see in Firebug, that the ajax call is processed twice.

GET /home/add_note?id=39 200 OK 601ms GET /home/add_note?id=39 200 OK 1154ms 

How it is possible? What could be wrong?

4
  • Is all other javascript and Ajax behaving normally? Perhaps you've included the rails.js twice somehow, assigning the link handler 2x? Commented Nov 24, 2011 at 16:07
  • Actually, I don't understand how the assets in Rails 3.1 works. Because in the /app/assets/javasripts I have only the file application.js, that is empty and in the application.html.erb I have <%= javascript_include_tag "application" %>. If I take a look to the source of HTML page, I see there <script src="/assets/jquery.js?body=1" type="text/javascript"></script> and <script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>. But in my directories these files aren't. Commented Nov 24, 2011 at 16:13
  • Check out the documentation on the assets pipeline which is new to Rails 3.1. The jQuery and UJS javascripts are included via gems, and can be seen in your Gemfile. But unfortunately, if all you're seeing for javascript includes are those two files, it probably isn't an issue of any handler being included 2x. Commented Nov 24, 2011 at 16:28
  • That's weird... the same code works my fine in a project in Rails 3. Commented Nov 24, 2011 at 16:29

2 Answers 2

4

This likely has to do with the assets pipeline, although the asset pipeline documentation wasn't very useful here. You might have application*.js.* included twice in the asset path. Run:

$ find . -name "application*.js*" ./app/assets/javascripts/application.js ./public/assets/application.js ./public/assets/application-5f5e14d05ab99cac084b66cb87bbeec8.js ./public/assets/application-5f5e14d05ab99cac084b66cb87bbeec8.js.gz ./public/assets/application-95fca227f3857c8ac9e7ba4ffed80386.js.gz ./public/assets/application-95fca227f3857c8ac9e7ba4ffed80386.js ./public/assets/application.js.gz 

If you see a picture as above, delete the generated assets from public/assets.

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

Comments

0

When you include js twice it will call two times

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.