Forum: Ruby on Rails Ajax/View Best Practices

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Cb21818896b28255ccebd05e257ac944?d=identicon&s=25 Brian Donahue (madscene)
on 2006-02-11 03:09
So, I'm rolling along learning Rails, finally starting playing with
Ajax, and am embarrassed I waited so long because it's so darn easy in
Rails.  Anyway... I did run into a problem.

I'm trying to make a basic dynamic list, with a text box at the bottom
where you can add an item into the list, and delete links next to each
item to remove.  I want to be able to show more than one of these lists
on the same page.  So, I created a partial for the div containing the
list, and another partial for the display of each list item.  The ajax
for adding one does an update  :position => "after".  The code for
deleting reloads the whole list from the DB (wasn't sure if there is an
easy way to dynamically remove one list item?  I tried to set the ID of
the div with a variable so that the partials could properly set the
:update param in the ajax code.  The problem is, when I render the
partial it doesn't get the variable because it is only loaded on the
first page load.  I know this is a pretty typical use of rails/ajax, so
can someone enlighten me on how best to do this?  Hopefully I've
explained sufficiently.  Feel free to ask for clarification.


This topic is locked and can not be replied to.