As you know, when you upgrade from Rails 2 to 3 you replace this:
link_to_remote "more", :url => {...}
with this:
link_to "more", {...}, :remote => true
But how do you handle the :update option in link_to_remote? In Railscast #205 Ryan Bates demonstrates link_to
with :remote
and a server response that includes JavaScript code to update a particular element in a page, but this practice seems wrong to me. I want my server's response to be a simple HTML fragment which is easy to test and which can be used by different pages (clients) in different ways. I don't think the server should have to know the ID of the target element on the requesting page as it ties the action to the page (a mini-client) and therefore makes it less general (it also feels uglier than a pure HTML response).
So, to be explicit, is there a way to do something like this:
link_to_remote "more", :url => {...}, :update => "products-list"
with Rails 3 and UJS? Or do I have to write JavaScript to capture the server's HTML response and insert it into the right element on the page?
If the latter, please describe the best approach (can link_to
's :remote
option be used at all?).