I have been try to make a page where a user can add something to a list and then delete something from the same list all without re-loading the page. The adding part is easy, but the deleting part is turning out to be a pain.
A user by the name of Philip gave me some very helpful hints: Put the snip of rHTML that needs to refresh into a partial. Include it the normal way, like this:
<%= render :partial => 'my_partial' %>
Now wire link_to_remote up to an action that looks like this:
return unless request.xhr?
render :update do |page| # <-- I call that rjs sometimes!
page.replace_html 'refresh_me', :partial => 'my_partial'
(Question for the lifers - is it _really_ "almost anything"? Or is it
I haven't come across anything that I couldn't send back yet...
This does not work, however, it just reloads the entire page within the
list. Does anyone have any other ideas or sugestions. I realize that I
am probably implementing the above code wrong, but I have tried every
way that I can think of. Thanks,
What does your link_to_remote look like? It should just update the 'refresh_me' div with the result of the partial 'my_partial'.
Also, if you want to delete an item, another idea would be to assign each item it's own id. Say
<div id='my_item_123'>This is item 123</div>
Then in your delete action (or link to method for that action in a callback on success) use an event to simply remove that element from the page. Then nothing has to update, and the item simply goes away after deleting it.