I would like to use the link_to_remote method in my controller so I can
update a list within my .rhtml file without having to re-load the entire
page. Basically, what I am doing is adding stuff to a list and then
allowing that stuff to be deleted from the list if the user so chooses -
all with the built-in AJAX functionality. The idea is that I do not want
the entire page to re-load. I’m thinking that there is an eval() method
that I can use but have not yet discovered it. Anyone have any ideas?
try something like
render_to_string :inline => “<%= link_to_remote … %>”
-fouad
On Jun 27, 1:01 am, Shandy N. [email protected]
Shandy N. wrote:
I would like to use the link_to_remote method in my controller so I can
update a list within my .rhtml file without having to re-load the entire
page. Basically, what I am doing is adding stuff to a list and then
allowing that stuff to be deleted from the list if the user so chooses -
all with the built-in AJAX functionality. The idea is that I do not want
the entire page to re-load. I’m thinking that there is an eval() method
that I can use but have not yet discovered it. Anyone have any ideas?
Put the snip of rHTML that needs to refresh into a partial. Include it
the
normal way, like this:
Now wire link_to_remote up to an action that looks like this:
def my_action
return unless request.xhr?
render :update do |page| # ← I call that rjs sometimes!
page.replace_html ‘refresh_me’, :partial => ‘my_partial’
end
end
The deal is that almost* anything you can pass to render, you can also
pass
to the second argument to JavaScriptGenerator#replace_html.
The first code injects raw HTML into your page as it renders, before it
goes
over the wire. The second snip renders the partial, then creates
JavaScript
containing Element.update(‘refresh_me’, ‘’). This
goes over the wire, and the Ajax handlers from prototype.js will replace
the
innerHTML member of that
(Question for the lifers - is it really “almost anything”? Or is it
“anything”!?)
–
Phlip
Test Driven Ajax (on Rails) [Book]
“Test Driven Ajax (on Rails)”
assert_xpath, assert_javascript, & assert_ajax
I tried your idea and it seems to run (or at least it does not complain
at all about any of the code), but when I attempt to delete the entry
that I just added, nothing happens.