How to overwrite routes behavior to add a “delete” route to every resource

23rd Lug 2012Ruby on Rails, , , ,

This is useful when a custom route is needed for every resource.

config/initializers/delete_resource_route.rb

module DeleteResourceRoute
  def resources(*args, &block)
    super(*args) do
      yield if block_given?
      member do
        get :delete
        delete :delete, action: :destroy
      end
    end
  end
end
ActionDispatch::Routing::Mapper.send(:include, DeleteResourceRoute)

From: #77 Destroy without JavaScript (revised) Railscast