简体   繁体   中英

Ruby on Rails Error, Routing Error No route matches [GET] “/users”, Devise

So I added devise to my Rails project and the generated a user scaffold called, users , after I did that I tried to enter the /users section of my site but I can only access a few branches of it like: /users/sign_in , /users/sign_up , /users/edit , etc.

This is the error page that I get:

[Error page]: 在此处输入图片说明

This is my routes file:

Stoabook::Application.routes.draw do
  devise_for :users
  resources :statuses
  root to: 'statuses#index'
end

And this is what I get when I run rake routes:

                  Prefix Verb   URI Pattern                    Controller#Action
    new_user_session GET    /users/sign_in(.:format)       devise/sessions#new
        user_session POST   /users/sign_in(.:format)       devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format)      devise/sessions#destroy
       user_password POST   /users/password(.:format)      devise/passwords#create
   new_user_password GET    /users/password/new(.:format)  devise/passwords#new
  edit_user_password GET    /users/password/edit(.:format) devise/passwords#edit
                     PATCH  /users/password(.:format)      devise/passwords#update
                     PUT    /users/password(.:format)      devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)        devise/registrations#cancel
   user_registration POST   /users(.:format)               devise/registrations#create
new_user_registration GET    /users/sign_up(.:format)       devise/registrations#new
edit_user_registration GET    /users/edit(.:format)          devise/registrations#edit
                     PATCH  /users(.:format)               devise/registrations#update
                     PUT    /users(.:format)               devise/registrations#update
                     DELETE /users(.:format)               devise/registrations#destroy
            statuses GET    /statuses(.:format)            statuses#index
                     POST   /statuses(.:format)            statuses#create
          new_status GET    /statuses/new(.:format)        statuses#new
         edit_status GET    /statuses/:id/edit(.:format)   statuses#edit
              status GET    /statuses/:id(.:format)        statuses#show
                     PATCH  /statuses/:id(.:format)        statuses#update
                     PUT    /statuses/:id(.:format)        statuses#update
                     DELETE /statuses/:id(.:format)        statuses#destroy
                root GET    /                              statuses#index

I have tried restarting my server many times.

EDIT:

I didn't Scaffold it. I used the devise helper:

rails generate devise user

It seems you did not actually scaffold users, but you used the devise generator. That is a big difference. A regular scaffold generates all CRUD routes. The devise generator on the other hand does not. It is solely concerned with authentication resources, such as signing up or in.

If you want more routes you should generate your own users controller. This way you can overwrite or expand on what devise already provided under the hood.It is probably a wise plan to check the github page and wiki for devise.

Ps Please try to avoid scaffolding if possible. Yes, it speed things up, but does so at the expanse of learning what is actually going on. Moreover, it usually creates more than you actually need. If you forget to remove unused generated code, your code becomes bloated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM