Skip to content

Instantly share code, notes, and snippets.

@jmuheim
Forked from jasoncodes/_form.html.haml
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmuheim/322c1267affa7a220efa to your computer and use it in GitHub Desktop.
Save jmuheim/322c1267affa7a220efa to your computer and use it in GitHub Desktop.
/ ...
- f.inputs do
= f.hidden_field :lock_version
/ ...
class AddLockingToFoo < ActiveRecord::Migration
def change
add_column :foos, :lock_version, :integer, :default => 0, :null => false
end
end
class FoosController < Admin::BaseController
inherit_resources
include UpdateLock
end
module UpdateLock
def update
raise ActiveRecord::MissingAttributeError, "Lock version missing" if params[resource_instance_name][:lock_version].blank?
super
rescue ActiveRecord::StaleObjectError
flash.now[:error] = t(
'flash.actions.update.stale',
:default => '%{resource_name} has been updated by another user.',
:resource_name => resource.class.human_name
)
render :edit, :status => :conflict
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment