user984621
user984621

Reputation: 48513

Rails 3.1 - calling AJAX request twice

<%=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?

Upvotes: 2

Views: 2240

Answers (2)

vijay chouhan
vijay chouhan

Reputation: 1012

When you include js twice it will call two times

Upvotes: 0

gliptak
gliptak

Reputation: 3670

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.

Upvotes: 4

Related Questions