过去几天我一直在学习本教程,最后在第 7 章遇到了障碍。
正是在这一步中,routes.rb 中的行:
get "users/new"
被替换为
resource :users
完成此操作后,访问时出现路由错误
http://localhost:3000/users/1 - No route matches [GET] "/users/1"
而不是此处显示的其他“未知操作”错误。
根据说明,我的 routes.db 文件如下所示:
SampleApp::Application.routes.draw do
resource :users
root "static_pages#home"
match '/signup', to: 'users#new', via: 'get'
match '/help', to: 'static_pages#help', via: 'get'
match '/about', to: 'static_pages#about', via: 'get'
match '/contact', to: 'static_pages#contact', via: 'get'
end
'rake routes' 的输出显示:
Prefix Verb URI Pattern Controller#Action
users POST /users(.:format) users#create
new_users GET /users/new(.:format) users#new
edit_users GET /users/edit(.:format) users#edit
GET /users(.:format) users#show
PATCH /users(.:format) users#update
PUT /users(.:format) users#update
DELETE /users(.:format) users#destroy
root GET / static_pages#home
signup GET /signup(.:format) users#new
help GET /help(.:format) static_pages#help
about GET /about(.:format) static_pages#about
contact GET /contact(.:format) static_pages#contact
有没有人有任何洞察力来解决这个问题?非常感谢。