module ActiveScaffold::Actions::Delete

Public Class Methods

included(base) click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 3
def self.included(base)
  base.before_filter :delete_authorized_filter, :only => [:destroy]
end

Public Instance Methods

destroy() click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 7
def destroy
  params.delete :destroy_action
  process_action_link_action(:destroy) do |record|
    do_destroy(record)
  end
end

Protected Instance Methods

delete_authorized?(record = nil) click to toggle source

The default security delegates to ActiveRecordPermissions. You may override the method to customize.

# File lib/active_scaffold/actions/delete.rb, line 54
def delete_authorized?(record = nil)
  (!nested? || !nested.readonly?) && (record || self).authorized_for?(:crud_type => :delete)
end
delete_ignore?(record = nil) click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 58
def delete_ignore?(record = nil)
  (nested? && nested.readonly?) || !self.authorized_for?(:crud_type => :delete)
end
destroy_find_record() click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 34
def destroy_find_record
  @record = find_if_allowed(params[:id], :delete)
end
destroy_respond_to_html() click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 16
def destroy_respond_to_html
  flash[:info] = as_(:deleted_model, :model => ERB::Util.h(@record.to_label)) if self.successful?
  return_to_main
end
destroy_respond_to_js() click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 21
def destroy_respond_to_js
  do_refresh_list if successful? && active_scaffold_config.delete.refresh_list && !render_parent?
  render(:action => 'destroy')
end
destroy_respond_to_json() click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 30
def destroy_respond_to_json
  render :json => successful? ? '' : response_object, :only => active_scaffold_config.list.columns.names, :status => response_status
end
destroy_respond_to_xml() click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 26
def destroy_respond_to_xml
  render :xml => successful? ? '' : response_object, :only => active_scaffold_config.list.columns.names, :status => response_status
end
do_destroy(record) click to toggle source

A simple method to handle the actual destroying of a record May be overridden to customize the behavior

# File lib/active_scaffold/actions/delete.rb, line 40
def do_destroy(record)
  record ||= destroy_find_record
  begin
    self.successful = record.destroy
  rescue StandardError => ex
    flash[:warning] = as_(:cant_destroy_record, :record => ERB::Util.h(record.to_label))
    self.successful = false
    logger.debug ex.message
    logger.debug ex.backtrace.join("\n")
  end
end

Private Instance Methods

delete_authorized_filter() click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 64
def delete_authorized_filter
  link = active_scaffold_config.delete.link || active_scaffold_config.delete.class.link
  raise ActiveScaffold::ActionNotAllowed unless send(link.security_method)
end
destroy_formats() click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 69
def destroy_formats
  (default_formats + active_scaffold_config.formats + active_scaffold_config.delete.formats).uniq
end