How do I remove the Devise route to sign up?

后端 未结 15 2408
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-07 07:36

I\'m using Devise in a Rails 3 app, but in this case, a user must be created by an existing user, who determines what permissions he/she will have.

Because of this, I

15条回答
  •  悲&欢浪女
    2020-12-07 08:10

    I've found this to work well without messing with routes or adding application controller methods. My approach is to override the devise method. Add this to app/controllers/devise/registrations_controller.rb I've omitted the other methods for brevity.

    class Devise::RegistrationsController < DeviseController
      ...
      # GET /resource/sign_up
      def new
        redirect_to root_path
      end
      ....
    end
    

    Also to remove illusion that this path is still reachable from other views you might also want to remove this code from app/views/devise/shared/_links.erb

    <%- if devise_mapping.registerable? && controller_name != 'registrations' %>
      <%= link_to "Sign up", new_registration_path(resource_name) %>
    <% end -%>

提交回复
热议问题