Hi, I'm looking for recommendations as to the best way to create & manage buttons that perform an action on an object and then update a portion of the page with a response from the server.
This was relatively simple in Rails 2.3 land: the now removed link_to_remote method ( http://apidock.com/rails/ActionView/Helpers/PrototypeHelper/link_to_remote) would automagically generate javascript that would ask your Rails app for a snippet and then replace part of the page with that snippet. It was, of course, messy as hell, which I think is why it got removed. Looking for something that does something similar in 3.x land hasn't gotten me very far: the consensus seems to be "write your own damn javascript". We've done so so far, but it's never been quite as easy as the old helper methods. Also, I'm haunted by the "doing it wrong" spectre: the way we're doing it is simply aping the way the 2.3 helpers used to work, except with hand written UJS rather than generated RJS. The example I'm working on right now is a button that, while editing a user, allows the administrator to forgive a user's past invoices. The button is within an existing form. The code, right now, is bloody terrible: = link_to "Cancel Outstanding Invoices", cancel_outstanding_invoices_user_path(@user), :class => "btn btn-danger", :id => "cancel-outstanding-invoices", :remote => true, :method => :post :javascript $('#outstanding-invoices').bind('ajax:success', function(event, data) { $('#outstanding-invoices').html(data); }); The Rails action simply performs a "render :text =>". There's a whole bunch of better ways I can think of doing the above - even ways that allow me to make the Javascript code completely generic. However, I'd rather see how others do it first. -- Michael Pearson -- You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To post to this group, send email to rails-oceania@googlegroups.com. To unsubscribe from this group, send email to rails-oceania+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.