In an ERB Rails view
<%= link_to("Destroy", foos_path(1), :method => :delete, :confirm => "Are you sure?") %>
With a link_to lik开发者_运维知识库e the above you can process the delete for a foo with an ID of 1. How do make it remote and (a) still control being redirected to a page of my control or (b) call custom JavaScript (the goal of which would be jQuery to refresh a list)
Add :remote => true
to the link_to will create a remote link.
In your controller method at the end put
respond_to do |format|
format.js { render "my_method"}
end
You can omit the name of the ajax file if it's the same name as the method.
In my_method.js.erb simply call javascript functions, and you can embed erb ie:
$("#someDiv").load(<%= @some_value $>);
You can redirect to another page using standard javascript/jquery if you choose.
精彩评论