在rails route.rb中手动键入的等效资源是什么?

时间:2019-06-23 21:49:41

标签: ruby-on-rails ruby-on-rails-5

假设rails new myapp && cd myapp && rails g scaffold Teacher

routes.rb包含resources :teachers

routes.rb中此行的手动键入的等效项是什么? (我问的原因是因为我想保留最多的路线,但要编辑一些路线)

1 个答案:

答案 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'