Skip to content

Instantly share code, notes, and snippets.

@libryder
Created February 19, 2012 23:34
Show Gist options
  • Select an option

  • Save libryder/1866494 to your computer and use it in GitHub Desktop.

Select an option

Save libryder/1866494 to your computer and use it in GitHub Desktop.
Simple solution to enable transaction rollbacks
class ApplicationController < ActionController::Base
around_filter :check_dry_run
def check_dry_run
ActiveRecord::Base.transaction do
yield
raise ActiveRecord::Rollback, "dry_run specified; no changes made" if @dry_run
end
end
end
class SampleController < ApplicationController
def create
if params[:dry_run].blank?
@dry_run = true
else
@dry_run = false
end
@sample = Sample.new params[:sample]
@sample.save
respond_with @sample
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment