Created
January 30, 2011 14:00
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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