rails link_to :remote
You can bind to ajax calls like this:
<%= link_to my_path, method: :delete, confirm: 'Delete?', class: 'link-delete', 'data-message' => 'Are you sure?', 'data-severity' => 'danger', :remote => true do %> <i class="icon-trash"></i><% end %>$('.link-delete').bind('ajax:beforeSend', function() { $('#mySpinner').show();});$('.link-delete').bind('ajax:complete', function() { $('#mySpinner').hide();});
You don't need to combine the two. Just use the format.js to call the javascript.
In your controller:
Controller
def my_method #code here respond_to do |format| format.js {} end end
my_method.html.erb
<div id = "link-delete"></div>
my_method.js.erb
$("#link-delete").html("<%= escape_javascript(render(:partial => "text_message"))%>");
_text_message.html.erb
<p>Loading...</p>