What if I have an API method and a contoller/view method with the same name in RoR?
- by Chad Johnson
Suppose I want to be able to view a list of products on my site by going to /product/list. Great. So this uses my 'list' view and outputs some HTML which my web browser will render.
But now suppose I want to provide a REST API to my client where they can get a list of their products. So I suppose I'd have them authenticate with oAuth and then they'd call /product/list which would return a JSON array of their products.
But like I said earlier, /product/list displays an HTML web page. So, I have a conflict.
What is normal practice as far as providing APIs in Rails? Should I have a subdirectory, 'api', in /app/controller, and another 'product' controller? So my client would go to /api/product/list to get a list of their products?
I'm a bit new to RoR, so I don't have the best grasp of the REST functionality yet, but hopefully my question makes sense.