Topic: Help moving JS from the view to the .js file

Hi,

I have a view in which there is a table.  For each rows, I have to query a web service and since it's a little long, I did some ajax that will render the page, then update a div inside each row with the web service answer.  The JS code is currently in the view itself and I'd like to move it to application.js or xxx.js.coffee but can't get it to work.

My view has

 
<% @thisthing.each do |b| %>
<% @thisotherthing.each do |c| %>
(...) 

then a table where each row has :

Some interesting things shown here and another line with
<div id="bug_<%= b.id %>"> Loading </div> 

at the end of this view, I have the following

<% @thisthing.each do |b| %>
<% @thisotherthing.each do |c| %>
<% if b.id == c.bug_id  %>
<script>
  $.ajax({
      url: "/top10/wscall?name=<%= c.value %>",
      cache: false,
      success: function(html){
        $("#bug_<%= b.id %>").replaceWith(html);
      }
  });
</script>
<% end %>
<% end %>
<% end %>

It works but I would like to move this ajax stuff at its proper place.  I tried the data-url kind of stuff found on http://railscasts.com/episodes/324-pass … javascript but it doesn't work and I believe it's because of my c.value or b.id that the JS file doesn't know about...

Thanks!