How do I remove the Devise route to sign up?

后端 未结 15 2419
佛祖请我去吃肉
佛祖请我去吃肉 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 had similar issue tried to remove devise_invitable paths for create and new :

    before:

     devise_for :users
    

    rake routes

    accept_user_invitation GET    /users/invitation/accept(.:format)           devise/invitations#edit
           user_invitation POST   /users/invitation(.:format)                  devise/invitations#create
       new_user_invitation GET    /users/invitation/new(.:format)              devise/invitations#new
                           PUT    /users/invitation(.:format)                  devise/invitations#update
    

    after

    devise_for :users , :skip => 'invitation'
    devise_scope :user do
      get "/users/invitation/accept", :to => "devise/invitations#edit",   :as => 'accept_user_invitation'
      put "/users/invitation",        :to => "devise/invitations#update", :as => nil
    end
    

    rake routes

    accept_user_invitation GET    /users/invitation/accept(.:format)                 devise/invitations#edit
                           PUT    /users/invitation(.:format)                        devise/invitations#update
    

    note 1 devise scope https://github.com/plataformatec/devise#configuring-routes

    note 2 I'm applying it on devise_invitable but it will work with any devise *able feature

    Important note: see that devise_scope is on user not users ? that's correct, watch out for this ! It can cause lot of pain giving you this problem:

    Started GET "/users/invitation/accept?invitation_token=xxxxxxx" for 127.0.0.1 
    Processing by Devise::InvitationsController#edit as HTML
      Parameters: {"invitation_token"=>"6Fy5CgFHtjWfjsCyr3hG"}
     [Devise] Could not find devise mapping for path "/users/invitation/accept?  invitation_token=6Fy5CgFHtjWfjsCyr3hG".
    This may happen for two reasons:
    
    1) You forgot to wrap your route inside the scope block. For example:
    
      devise_scope :user do
         match "/some/route" => "some_devise_controller"
      end
    
     2) You are testing a Devise controller bypassing the router.
       If so, you can explicitly tell Devise which mapping to use:
    
        @request.env["devise.mapping"] = Devise.mappings[:user]
    

提交回复
热议问题