假设rails new myapp && cd myapp && rails g scaffold Teacher
routes.rb
包含resources :teachers
routes.rb
中此行的手动键入的等效项是什么? (我问的原因是因为我想保留最多的路线,但要编辑一些路线)
答案 0 :(得分:4)
用户唯一需要做的两件事是查看某些数据(“获取”)或删除记录(“ destroy”)或插入新记录(“创建”)
支持这种情况:
resources :teachers, only: [:show, :destroy, :create]
对于“手动”路线,您可以这样表示:show
路线:
get '/teachers/:id', to: 'teachers#show'
完全等效如下:
get '/teachers' => 'teachers#index'
get '/teachers/:id' => 'teachers#show'
get '/teachers/new' => 'teachers#new'
post '/teachers' => 'teachers#create'
get '/teachers/:id/edit' => 'teachers#edit'
put '/teachers' => 'teachers#update'
delete '/teachers' => 'teachers#destroy'