0

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?

2 Answers 2

4

Just use a single post route:

post "/images/upload", to: "images#upload", as: :images_upload
Sign up to request clarification or add additional context in comments.

Comments

1

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]

2 Comments

I'm trying to follow the advice from this comment stackoverflow.com/a/42784598/12238373. I'm not creating an Image object, but rather I'm just uploading an image to Cloudinary, and returning the URL to the client, nothing else. Does it still seem appropriate to remove upload method and assign this code to create method?
Sure. It is a Rails convention that HTTP POST requests are handled by the create method of the controller.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.