gpt4 book ai didi

ruby-on-rails - 资源的匹配和动词等价物是什么?

转载 作者:行者123 更新时间:2023-12-04 00:45:15 25 4
gpt4 key购买 nike

routing guide它说“路由文件中的单个条目,例如 resources :photos 在您的应用程序中创建 七个 八个不同的路由,所有路由都映射到照片 Controller : ”。

    photos GET    /photos(.:format)          photos#index
POST /photos(.:format) photos#create
new_photo GET /photos/new(.:format) photos#new
edit_photo GET /photos/:id/edit(.:format) photos#edit
photo GET /photos/:id(.:format) photos#show
PATCH /photos/:id(.:format) photos#update
PUT /photos/:id(.:format) photos#update
DELETE /photos/:id(.:format) photos#destroy

如何使用 match 和动词方法(getpostpatch, 删除)?

最佳答案

match '/photos'          => 'photos#index',   via: :get
match '/photos' => 'photos#create', via: :post
match '/photos/new' => 'photos#new', via: :get, as: 'new_photo'
match '/photos/:id/edit' => 'photos#edit', via: :get, as: 'edit_photo'
match '/photos/:id' => 'photos#show', via: :get, as: 'photo'
match '/photos/:id' => 'photos#update', via: :patch
match '/photos/:id' => 'photos#update', via: :put
match '/photos/:id' => 'photos#destroy', via: :delete

get    '/photos',          to: 'photos#index'
post '/photos', to: 'photos#create'
get '/photos/new', to: 'photos#new', as: 'new_photo'
get '/photos/:id/edit', to: 'photos#edit', as: 'edit_photo'
get '/photos/:id', to: 'photos#show', as: 'photo'
patch '/photos/:id', to: 'photos#update'
put '/photos/:id', to: 'photos#update'
delete '/photos/:id', to: 'photos#destroy'

关于ruby-on-rails - 资源的匹配和动词等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11603417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com