deltakroneker
deltakroneker

Reputation: 771

Rails: How to define custom route but remove default ones

I want to have an Image controller and allow single endpoint such as:

/images/upload

but disable all the other default ones.

resources :images, only: [] do
 collection do
  post "upload"
 end
end

This is my current approach that does the job, but is it the right one? Is there some sort of :none keyword to disable default routes? Or should i not use resources and do it some other way?

Upvotes: 0

Views: 158

Answers (2)

spickermann
spickermann

Reputation: 106872

IMO uploading an image can be understood as creating an image, therefore I would simply use the create method instead of an upload method:

resources :images, only: [:create]

Upvotes: 1

Nicolas Blanco
Nicolas Blanco

Reputation: 11299

Just use a single post route:

post "/images/upload", to: "images#upload", as: :images_upload

Upvotes: 4

Related Questions