So im trying to do json calls on my rails app, and i want to use a parameter in my namespace route. in routes.rb i have this :
namespace :api do
resources :forescast do
end
end
that gives my route 127.0.0.1:3000/api/forecast.json that works but what i want is to put a parameter after forecast,not after .json, tha i want to use in my controller as a param something like:
127.0.0.1:3000/api/forecast/[service_name].json
i know i have to put it in routes.rb but i dont know how to make it. The outcome would be a json with data of that specific service, not all of them. I know i could make it as param at the final of the route. But im looking for a way to get it in that position of the route and use it as a param in my controller.
There is an exemple of how i would like it to be: :location begin a param to use in my controller.
CodePudding user response:
Try to change this on routes.rb
get 'api/forecast/service_name:' , to: 'api/forecasts#index'