Skip to content

Instantly share code, notes, and snippets.

@ahmedrb
Created January 30, 2011 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ahmedrb/802875 to your computer and use it in GitHub Desktop.
Save ahmedrb/802875 to your computer and use it in GitHub Desktop.
adds a GET 'delete' action to all singular and plural routes by default
# puts this file in config/initializers
#
# adds GET /resource/:id/delete to all singular and plural routes
# works with the :only and :except options for resources() and resource()
module ActionDispatch::Routing::Mapper::Resources
class Resource
# nodoc
def default_actions_with_delete_action(*args)
actions = default_actions_without_delete_action(*args)
[actions, :delete].flatten
end
alias_method_chain :default_actions, :delete_action
end
# nodoc
def resource_with_delete_action(*resources, &block)
resource_without_delete_action(*resources) do
block.call if block
get(:delete, :on => :member) if parent_resource.actions.include?(:delete)
end
self
end
alias_method_chain :resource, :delete_action
# nodoc
def resources_with_delete_action(*resources, &block)
resources_without_delete_action(*resources) do
block.call if block
get(:delete, :on => :member) if parent_resource.actions.include?(:delete)
end
self
end
alias_method_chain :resources, :delete_action
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment