Created
February 23, 2011 10:39
-
-
Save clyfe/840267 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/as_i92.rb | |
# ======================================================================== | |
# resolution for https://github.com/vhochstein/active_scaffold/issues/92 # | |
# currently monkeypatching the bug, to be deleted on official fix # | |
# ======================================================================== | |
module ActiveScaffold::Actions | |
module Update | |
protected | |
# A complex method to update a record. The complexity comes from the support for subforms, and saving associated records. | |
# If you want to customize this algorithm, consider using the +before_update_save+ callback | |
def do_update | |
do_edit | |
update_save | |
end | |
def update_save | |
begin | |
active_scaffold_config.model.transaction do | |
@record = update_record_from_params(@record, active_scaffold_config.update.columns, params[:record]) | |
before_update_save(@record) | |
self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit | |
if successful? | |
@record.save! and @record.save_associated! | |
after_update_save(@record) | |
else | |
raise ActiveRecord::Rollback, "don't save associations unless record is valid" | |
end | |
end | |
rescue ActiveRecord::RecordInvalid | |
rescue ActiveRecord::StaleObjectError | |
@record.errors.add(:base, as_(:version_inconsistency)) | |
self.successful=false | |
rescue ActiveRecord::RecordNotSaved | |
@record.errors.add(:base, as_(:record_not_saved)) if @record.errors.empty? | |
self.successful = false | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment