Thynkon / MAW2.1-KeepIt-Back

MIT License
0 stars 0 forks source link

Incorrect route configuration #12

Closed SemicolonManifest closed 1 year ago

SemicolonManifest commented 1 year ago
resources :books, only: [:index, :show] do
    collection do
      get 'search'
      put '/:id/upvote', to: 'books#upvote'
      put '/:id/downvote', to: 'books#downvote'
      delete '/:id/unvote', to: 'books#unvote'
      put '/:id/track', to: 'books#track'
    end
  end

"collection" is for the whole ressource (without '/:id/'), not a specific member. It should be done that way when you use the id of a member of a resource:

member do
  put 'upvote'
  put 'downvote'
  delete 'unvote'
  put 'track'
end

You can also note that the "to:" are unnecessary, it already knows where to go

You can find some documentation on the subject there: https://guides.rubyonrails.org/routing.html#adding-more-restful-actions