I'm using 4.8.2 version of api-paginationwith Rails API 5.2.2 and will_pagiante gem.
Here is the links generated in the JSON response:
..
"links": {
"self": "http://localhost:3000/api/countries/be/addresses?page%5Bnumber%5D=1&page%5Bsize%5D=30",
"first": "http://localhost:3000/api/countries/be/addresses?page%5Bnumber%5D=1&page%5Bsize%5D=30",
"prev": null,
"next": "http://localhost:3000/api/countries/be/addresses?page%5Bnumber%5D=2&page%5Bsize%5D=30",
"last": "http://localhost:3000/api/countries/be/addresses?page%5Bnumber%5D=2&page%5Bsize%5D=30"
}
When I tried to hit manually the next link URL as follows:
http://localhost:3000/api/countries/be/addresses?page[number]=2&page[size]=30
it fails to respond and returns the following error:
Started GET "/api/countries/be/addresses?page[number]=2&page[size]=30" for 127.0.0.1 at 2019-03-01 15:28:42 +0100
Processing by V1::Api::AddressesController#all_by_country as */*
Parameters: {"page"=>{"number"=>"2", "size"=>"30"}, "country_code"=>"be"}
Country Load (0.5ms) SELECT "countries".* FROM "countries" WHERE "countries"."code" = $1 LIMIT $2 [["code", "BE"], ["LIMIT", 1]]
+++++ <ActionController::Parameters {"page"=>{"number"=>"2", "size"=>"30"}, "controller"=>"v1/api/addresses", "action"=>"all_by_country", "country_code"=>"be"} permitted: false>
(1.3ms) SELECT COUNT(*) FROM "addresses" INNER JOIN "shops" ON "shops"."id" = "addresses"."shop_id" INNER JOIN "countries" ON "countries"."id" = "shops"."country_id" WHERE "countries"."code" = $1 [["code", "BE"]]
Completed 500 Internal Server Error in 4ms (ActiveRecord: 1.8ms)
NoMethodError (undefined method `to_i' for #<ActionController::Parameters:0x00007fec231c37e0>
Did you mean? to_s
to_h):
As you see I'm getting a Hash in params:
Parameters: {"page"=>{"number"=>"2", "size"=>"30"}, "country_code"=>"be"}
Here is the corresponding controller action:
def all_by_country
@addresses = Address.all_by_country(@country.code)
paginate(
json: @addresses,
include: ['shop', 'shop.country'],
status: paginated_response_status(@addresses)
)
end
What am I missing ? Thank you.
I'm using
4.8.2version ofapi-paginationwith Rails API5.2.2andwill_pagiantegem.Here is the links generated in the JSON response:
When I tried to hit manually the
nextlink URL as follows:it fails to respond and returns the following error:
As you see I'm getting a Hash in params:
Here is the corresponding controller action:
What am I missing ? Thank you.