这是我的 API 的样子:
module ServiceRequests
class API < Grape::API
version 'v1', using: :path
format :json
namespace :companies do
params do
requires :company_id, type: Integer, desc: "A Company Id"
end
resource :service_requests do
get :all do
Company.find(params[:company_id]).service_requests
end
end
end
end
end
我正在尝试像这样拨打电话:http://localhost/v1/companies/:company_id/service_requests/all
但是当我拨打电话时,我收到了错误No route matches [GET] "/v1/companies/1/service_requests/all"
工作代码:
module ServiceRequests
class API < Grape::API
version 'v1', using: :path
format :json
resource :companies do
params do
requires :company_id, type: Integer, desc: "A Company Id"
end
route_param :company_id do
resource :service_requests do
get do
Company.find(params[:company_id]).service_requests
end
end
end
end
end
end