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
  end
end

Protected Instance Methods

delete_authorized?(record = nil) click to toggle source

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

# File lib/active_scaffold/actions/delete.rb, line 63
def delete_authorized?(record = nil)
  authorized_for?(:crud_type => :delete)
end
destroy_find_record() click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 45
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.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new? ? '' : ": #{@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
  if successful? && active_scaffold_config.delete.refresh_list && !render_parent?
    do_search if respond_to? :do_search
    do_list
  end
  render(:action => 'destroy')
end
destroy_respond_to_json() click to toggle source
# File lib/active_scaffold/actions/delete.rb, line 37
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 33
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 41
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 51
def do_destroy
  @record ||= destroy_find_record
  begin
    self.successful = @record.destroy
  rescue
    flash[:warning] = as_(:cant_destroy_record, :record => @record.to_label)
    self.successful = false
  end
end

Private Instance Methods

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