i want to create a route to search an article
should be able to add the size or the page
like this
'/post/1/article/search?size=200&page=1
it will be good like this?
get '/post/:id/article/search/:size/:page
can i create that endpoint directly with rails?
namespace :api do
namespace :v1 do
resources :posts do
resources :articles
get /search/:size/:page
CodePudding user response:
Something like this should work:
namespace :api do
namespace :v1 do
resources :posts do
resources :articles do
collection do
get "/search/:size/:page", action: :search, defaults: { size: 200, page: 1 }
end
end
end
end
end
In your controller, you'll be able to access via: params[:size]
and params[:page]
.
NOTES