Devise routing: is there a way to remove a route from Rails.application.routes?

后端 未结 4 1140
温柔的废话
温柔的废话 2020-12-14 02:53

devise_for creates routes including a DELETE route, which we want to remove, and devise_for doesn\'t support an :except or :only

4条回答
  •  粉色の甜心
    2020-12-14 03:33

    Actually devise_for does support :skip and :only, for example (docs):

    devise_for :user, :skip => :registration
    

    This will skip all the registration controller's routes, rather than one specifically. You could then implement the routes you need. This seems cleaner than removing the route after the fact.

    UPDATE:

    Another possible solution is to use Rails' advanced constraints feature to block the unwanted route completely:

    # config/routes.rb
    constraints lambda {|req| req.url =~ /users/ && req.delete? ? false : true} do
      devise_for :users
    end
    

    Here is a post on using lambdas for route constraints. The request object is explained here. This might be the simplest solution.

提交回复
热议问题