# File lib/active_scaffold/actions/update.rb, line 8 def edit do_edit respond_to_action(:edit) end
# File lib/active_scaffold/actions/update.rb, line 13 def update do_update respond_to_action(:update) end
for inline (inlist) editing
# File lib/active_scaffold/actions/update.rb, line 19 def update_column do_update_column @column_span_id = params[:editor_id] || params[:editorId] end
override this method if you want to do something after the save
# File lib/active_scaffold/actions/update.rb, line 132 def after_update_save(record); end
override this method if you want to inject data in the record (or its associated objects) before the save
# File lib/active_scaffold/actions/update.rb, line 129 def before_update_save(record); end
A simple method to find and prepare a record for editing May be overridden to customize the record (set default values, etc.)
# File lib/active_scaffold/actions/update.rb, line 67 def do_edit @record = find_if_allowed(params[:id], :update) end
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
# File lib/active_scaffold/actions/update.rb, line 73 def do_update do_edit update_save end
# File lib/active_scaffold/actions/update.rb, line 106 def do_update_column @record = active_scaffold_config.model.find(params[:id]) if @record.authorized_for?(:crud_type => :update, :column => params[:column]) column = active_scaffold_config.columns[params[:column].to_sym] unless @record.column_for_attribute(params[:column]).nil? || @record.column_for_attribute(params[:column]).null if @record.column_for_attribute(params[:column]).default == true params[:value] ||= false else params[:value] ||= @record.column_for_attribute(params[:column]).default end end unless column.nil? params[:value] = column_value_from_param_value(@record, column, params[:value]) params[:value] = [] if params[:value].nil? && column.form_ui && column.plural_association? end @record.send("#{params[:column]}=", params[:value]) before_update_save(@record) @record.save after_update_save(@record) end end
# File lib/active_scaffold/actions/update.rb, line 25 def edit_respond_to_html if successful? render(:action => 'update') else return_to_main end end
# File lib/active_scaffold/actions/update.rb, line 32 def edit_respond_to_js render(:partial => 'update_form') end
should we refresh whole list after update operation
# File lib/active_scaffold/actions/update.rb, line 135 def update_refresh_list? active_scaffold_config.update.refresh_list end
# File lib/active_scaffold/actions/update.rb, line 35 def update_respond_to_html if params[:iframe]=='true' # was this an iframe post ? responds_to_parent do render :action => 'on_update', :formats => [:js], :layout => false end else # just a regular post if successful? flash[:info] = as_(:updated_model, :model => @record.to_label) return_to_main else render(:action => 'update') end end end
# File lib/active_scaffold/actions/update.rb, line 49 def update_respond_to_js if successful? do_refresh_list if update_refresh_list? && !render_parent? flash.now[:info] = as_(:updated_model, :model => @record.to_label) if active_scaffold_config.update.persistent end render :action => 'on_update' end
# File lib/active_scaffold/actions/update.rb, line 59 def update_respond_to_json render :text => response_object.to_json(:only => active_scaffold_config.update.columns.names), :content_type => Mime::JSON, :status => response_status end
# File lib/active_scaffold/actions/update.rb, line 56 def update_respond_to_xml render :xml => response_object.to_xml(:only => active_scaffold_config.update.columns.names), :content_type => Mime::XML, :status => response_status end
# File lib/active_scaffold/actions/update.rb, line 62 def update_respond_to_yaml render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.update.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status end
# File lib/active_scaffold/actions/update.rb, line 78 def update_save(options = {}) attributes = options[:attributes] || params[:record] begin active_scaffold_config.model.transaction do @record = update_record_from_params(@record, active_scaffold_config.update.columns, attributes) unless options[:no_record_param_update] 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 # some associations such as habtm are saved before saved is called on parent object # we have to revert these changes if validation fails raise ActiveRecord::Rollback, "don't save habtm associations unless record is valid" end end 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 rescue ActiveRecord::ActiveRecordError => ex flash[:error] = ex.message self.successful = false end end
# File lib/active_scaffold/actions/update.rb, line 3 def self.included(base) base.before_filter :update_authorized_filter, :only => [:edit, :update] base.helper_method :update_refresh_list? end