module ActiveScaffold::Actions::Update
Public Class Methods
included(base)
click to toggle source
# 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
Public Instance Methods
edit()
click to toggle source
# File lib/active_scaffold/actions/update.rb, line 8 def edit do_edit respond_to_action(:edit) end
update()
click to toggle source
# File lib/active_scaffold/actions/update.rb, line 13 def update do_update respond_to_action(:update) end
update_column()
click to toggle source
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
Protected Instance Methods
after_update_save(record)
click to toggle source
override this method if you want to do something after the save
# File lib/active_scaffold/actions/update.rb, line 127 def after_update_save(record); end
before_update_save(record)
click to toggle source
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 124 def before_update_save(record); end
do_edit()
click to toggle source
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 register_constraints_with_action_columns(nested.constrained_fields, active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested? @record = find_if_allowed(params[:id], :update) end
do_update()
click to toggle source
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 74 def do_update do_edit update_save end
do_update_column()
click to toggle source
# File lib/active_scaffold/actions/update.rb, line 99 def do_update_column # delete from params so update :table won't break urls, also they shouldn't be used in sort links too value = params.delete(:value) column = params.delete(:column).to_sym params.delete(:original_html) params.delete(:original_value) @record = find_if_allowed(params[:id], :read) if @record.authorized_for?(:crud_type => :update, :column => column) @column = active_scaffold_config.columns[column] value ||= unless @column.column.nil? || @column.column.null @column.column.default == true ? false : @column.column.default end unless @column.nil? value = column_value_from_param_value(@record, @column, value) value = [] if value.nil? && @column.form_ui && @column.plural_association? end @record.send("#{@column.name}=", value) before_update_save(@record) self.successful = @record.save after_update_save(@record) end end
edit_respond_to_html()
click to toggle source
# 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
edit_respond_to_js()
click to toggle source
# File lib/active_scaffold/actions/update.rb, line 32 def edit_respond_to_js render(:partial => 'update_form') end
update_refresh_list?()
click to toggle source
should we refresh whole list after update operation
# File lib/active_scaffold/actions/update.rb, line 130 def update_refresh_list? active_scaffold_config.update.refresh_list end
update_respond_to_html()
click to toggle source
# 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.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
update_respond_to_js()
click to toggle source
# File lib/active_scaffold/actions/update.rb, line 49 def update_respond_to_js if successful? && update_refresh_list? && !render_parent? do_search if respond_to? :do_search do_list end render :action => 'on_update' end
update_respond_to_json()
click to toggle source
# 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
update_respond_to_xml()
click to toggle source
# 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
update_respond_to_yaml()
click to toggle source
# 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
update_save(options = {})
click to toggle source
# File lib/active_scaffold/actions/update.rb, line 79 def update_save(options = {}) begin active_scaffold_config.model.db.transaction do @record = update_record_from_params(@record, active_scaffold_config.update.columns, params[:record]) unless options[:no_record_param_update] before_update_save(@record) @record.raise_on_save_failure = false self.successful = @record.save raise Sequel::Rollback unless successful? after_update_save(@record) end rescue Sequel::Error => err if Sequel::Plugins.const_defined?(:OptimisticLocking) and err.kind_of?(Sequel::Plugins::OptimisticLocking::Error) @record.errors.add(:base, as_(:version_inconsistency)) self.successful = false else raise err end end end
Private Instance Methods
edit_formats()
click to toggle source
# File lib/active_scaffold/actions/update.rb, line 144 def edit_formats (default_formats + active_scaffold_config.formats).uniq end
update_formats()
click to toggle source
# File lib/active_scaffold/actions/update.rb, line 147 def update_formats (default_formats + active_scaffold_config.formats + active_scaffold_config.update.formats).uniq end