Open AlejandroVirlan opened 4 years ago
Hello @AlejandroVirlan could you please attach at least the code of how those models relate? Seems to me you have a has_many
declaration with a singularized name. You could always do a i18n inference if you need it to respond with that name.
Either way, declaring a route like this:
match '/:resource/:id/custom' => 'apicustom#custom', via: :get
Yields a URL like this
http://localhost:3000/incidences/1/custom
Which is different from what you have posted that you tried consuming:
http://localhost:3000/api/v1/incidences/1/custom
This makes the API think you are consuming a regular nested resource with a model name of custom on the nested index action, and you probably don't have a model with that name 😂
You could edit the route to reflect the URL that you are consuming with:
match '/api/v1/:resource/:id/custom' => 'apicustom#custom', via: :get
I've been performing queries from the endpoint without
nested_resources
and it worked fine, but when I've tried to perform them withnested_resources
I couldn't make it work. I got this error:This is the endpoint that I tested:
http://localhost:3000/api/v1/incidences/1/incidence_trackings
I need to perform a custom query so the API returns the expected results; I've been reading your documentation and there is a section called "Extending base API actions", which I've tried and couldn't make it work. In this case that didn't work I got the BadRequest error (Bad hacker, stop bullying or I'll tell your mom!).
It seems that I need an id and a
nested_resource
.I've tried using any id from my resource, even if I don't need it, and it doesn't work either. This is the endpoint that I tested:
http://localhost:3000/api/v1/incidences/1/custom
Can I make an endpoint which doesn't require an id with a custom query.
This is my code:
routes.rb
api_controller.rb
apicustom_controller.rb
Thanks for your time.