TODO ==== respond_to is a way to quickly & compactly define presentation behaviors. Automatically responding is a nice goodie, but it feels awkward writing all those _type methods. # Presentation modules? class TracksController < ApplicationController def reorder Collection.transaction do @collection.tracks.find(:all, :lock => true).each do |track| track.position = params['collection_track'].index(track.id.to_s) + 1 track.save! end end end # Creates and includes a module in the controller then calls the action. respond_to :html do def reorder super rescue => rollback flash[:error] = rollback.message ensure redirect_back_or_to_collection end end end Here's a controller before and after automatic respond_to. # BEFORE class TracksController::Before < ApplicationController before_filter :find_collection # Reorder tracks in a collection. def reorder Collection.transaction do @collection.tracks.find(:all, :lock => true).each do |track| track.position = params['collection_track'].index(track.id.to_s) + 1 track.save! end end respond_to do |type| type.html { redirect_back_or_to_collection } type.js { render_tracks_update } type.xml { render :xml => @collection.to_xml } end rescue ActiveRecord::RecordNotSaved => maybe_invalid respond_to do |type| type.html { flash[:error] = ... } type.js { page.replace_html @collection.dom_id(:tracks), ... } type.xml { ... } end rescue => rollback respond_to do |type| type.html do flash[:error] = rollback.message redirect_back_or_to_collection end type.js { ... } type.xml { ... } end end end # AFTER: reorder with implicit Accepts class TracksController < ApplicationController before_filter :find_collection # Html reordering. def reorder_html yield rescue => rollback flash[:error] = rollback.message ensure redirect_back_or_to_collection end # Ajax reordering. def reorder_js yield render_tracks_update rescue ActiveRecord::RecordNotSaved => maybe_invalid render_errors_update @collection.dom_id(:tracks), @collection rescue => rollback render_exception_update @collection.dom_id('tracks-info') end # Xml reordering. def reorder_xml yield header['Location'] = collection_url(@collection) render :xml => @collection.to_xml rescue ActiveRecord::RecordNotSaved render :xml => @collection.errors.to_xml, :status => '400 Bad Request' end protected # Reorder tracks in a collection. def reorder Collection.transaction do @collection.tracks.find(:all, :lock => true).each do |track| track.position = params['collection_track'].index(track.id.to_s) + 1 track.save! end end end end # Other ideas?