Skip to content

Instantly share code, notes, and snippets.

@brianjlandau
Created January 25, 2011 15:35
Show Gist options
  • Select an option

  • Save brianjlandau/795075 to your computer and use it in GitHub Desktop.

Select an option

Save brianjlandau/795075 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
rescue_from ActiveRecord::StaleObjectError do |exception|
respond_to do |format|
format.html {
correct_stale_record_version
stale_record_recovery_action
}
format.xml { head :conflict }
format.json { head :conflict }
end
end
protected
def stale_record_recovery_action
flash.now[:error] = "Another user has made a change to that record "+
"since you accessed the edit form."
render :edit, :status => :conflict
end
end
class DestinationsController < ApplicationController
protected
def correct_stale_record_version
@destination.reload.attributes = params[:destination].reject do |attrb, value|
attrb.to_sym == :lock_version
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment