I have a table with a number of rows. The right most cell contains a link ''Delete'' when this is clicked I''d like that row to be removed from the table. How can I achieve this? The approach I''ve tried is wrapping the whole row in a div then when I the AJAX returns some HTML to update the div it should return nothing. Is this the best way? Any suggestions? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Planchant wrote:> I have a table with a number of rows. The right most cell contains a > link ''Delete'' when this is clicked I''d like that row to be removed from > the table. > > How can I achieve this? > > The approach I''ve tried is wrapping the whole row in a div then when I > the AJAX returns some HTML to update the div it should return nothing. > Is this the best way? Any suggestions?With your method, there''s going to be a lot of management around each row having it''s own div and getting refreshed. Instead, I''d recommend you do the refresh on the entire display of data rows. You may need to look into using the :collection parm with the render command (syntax is sometimes a little tricky with how to access the collection members). It''s quite DRY and easy to maintain. Assumptions here for purposes of demonstration are that your data has a "name" field, that you''re using a table layout, and that you are display :all rows from your data table. You should be able to get the idea here and adapt to your specific needs. I''m spewing off the top of my head here, no testing done on this, so I apologize for any typos or syntax errors. c. list action ***************** @data = Object.find(:all) list.rhtml view ***************** blah blah <%= render(:partial => "alldatarows", :object => @data) %> blah blah _alldatarows.rhtml partial ***************** <div id="alldatarows"> <table> <tr><th>Name</th><th>Action</th></tr> <%= render(:partial => "onedatarow", :collection => data) %> </table> </div> _onedatarow.rhtml partial ***************** <tr><td><%= onedatarow.name %></td><td><%= link_to_remote(''Delete'', :url => {:controller => ''whatever'', :action => ''deleterow'', :id = ''onedatarow.id''}) %></td></tr> deleterow action ***************** blah delete blah blah @data = Object.find(:all) deleterow.rjs template ***************** page[:alldatarows].replace_html :partial => ''alldatarows'', :object => @data -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks. I''ll try this method out. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Planchant wrote:> Thanks. I''ll try this method out.Hey - FYI, typo here, I think ":collection => data" should be ":collection => alldatarows" in this snippet: _alldatarows.rhtml partial ***************** <div id="alldatarows"> <table> <tr><th>Name</th><th>Action</th></tr> <%= render(:partial => "onedatarow", :collection => alldatarows) %> </table> </div> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Planchant wrote:> I have a table with a number of rows. The right most cell contains a > link ''Delete'' when this is clicked I''d like that row to be removed from > the table. > > How can I achieve this?Assign an id to every row and remove it with Protoype''s Element.remove <% row_id = your_custom_row_id_generating_helper %> <tr id="<%= row_id>"> <td>...</td> <td><%= link_to_function "Delete", "Element.remove(#{row_id})"%></td> </tr> There''s no need to for AJAX if no updated information is needed from the server. -- Sava Chankov --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---