Forum: Ruby on Rails Using a helper within a controller

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C4bfcc81ac9281cb905f38e97e4d4e0b?d=identicon&s=25 Shandy Nantz (snantz)
on 2007-06-27 00:01
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?
2ced34335d6aca14ea8dec9754191dd2?d=identicon&s=25 fmardini (Guest)
on 2007-06-27 00:21
(Received via mailing list)
try something like

render_to_string :inline => "<%= link_to_remote ... %>"

-fouad

On Jun 27, 1:01 am, Shandy Nantz <rails-mailing-l...@andreas-s.net>
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2007-06-27 06:02
(Received via mailing list)
Shandy Nantz 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:

  <div id='refresh_me'>
     <%= render :partial => 'my_partial' %>
  </div>

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', '<my partial html codes>'). This
goes over the wire, and the Ajax handlers from prototype.js will replace
the
innerHTML member of that <div id='refresh_me'> with the new version.

(Question for the lifers - is it _really_ "almost anything"? Or is it
"anything"!?)

--
  Phlip
  http://www.oreilly.com/catalog/9780596510657/
  "Test Driven Ajax (on Rails)"
  assert_xpath, assert_javascript, & assert_ajax
C4bfcc81ac9281cb905f38e97e4d4e0b?d=identicon&s=25 Shandy Nantz (snantz)
on 2007-06-27 21:33
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.
This topic is locked and can not be replied to.