module ActiveScaffold::Actions::Delete

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
  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 62
def delete_authorized?(record = nil)
  (!nested? || !nested.readonly?) && (record || self).send(:authorized_for?, :crud_type => :delete)
end
destroy_find_record() click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 42
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 15
def destroy_respond_to_html
  if self.successful?
    flash[:info] = as_(:deleted_model, :model => @record.to_label)
  else
    #error_message_for not available in controller...
    #flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br)
  end
  return_to_main
end
destroy_respond_to_js() click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 25
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 34
def destroy_respond_to_json
  render :text => successful? ? "" : response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status
end
destroy_respond_to_xml() click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 30
def destroy_respond_to_xml
  render :xml => successful? ? "" : response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status
end
destroy_respond_to_yaml() click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 38
def destroy_respond_to_yaml
  render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status
end
do_destroy() 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 48
def do_destroy
  @record ||= destroy_find_record
  begin
    self.successful = @record.destroy
  rescue Exception => ex
    flash[:warning] = as_(:cant_destroy_record, :record => @record.to_label)
    self.successful = false
    logger.debug ex.message
    logger.debug ex.backtrace.join("\n")
  end
end

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