I have a post request:
axios.post("/api/main/products/area_home_products.json"
then in routes.rb :
namespace :api do
namespace :dashboard do
....other routes...
end
namespace :main do
post '/products/area_home_products', to: 'products#area_home'
It was working all fine, then all of a sudden, with no significant changes to the controller action or the js file, I get:
No route matches [GET] "/api/main/products/area_home_products.json"
It is not the first time this happens, and I do not know why it happens nor how to solve it
Doing rake routes | grep area_home_products, gets me;
api_main_products_area_home_products POST /api/main/products/area_home_products(.:format) api/main/products#area_home
api_v1_products_area_home_products POST /api/v1/products/area_home_products(.:format) api/v1/products#area_home
You can use this method of api call. Also, update your route like this:
This is because either your request headers have problem as you are using .json in url which can mislead it as well as you are not using resourceful routing or your api is not properly configured.