I'm in the process of setting up my api and am using searchkick along with api-pagination/will_paginate. Here is how my index action is setup:
def index
if params[:q]
@cuisines = Cuisine.search params[:q], fields: [:name]
else
@cuisines = Cuisine.all
end
paginate json: @cuisines, each_serializer: Api::CuisineSerializer
end
When I hit this url:
http://api.test-site.dev/admin/cuisines?q="american"
I get the this exception thrown:
#<NoMethodError: undefined method `paginate' for #<Searchkick::Results:0x007fc586002618>>
While searching the web for a solution I was brought back here on git but to no avail:
paginate json: Cuisine.search("american").results
yeilds
#<ArgumentError: Must specify fields to search>
Specifying the fields brings me back to an exception similar to my original:
#<NoMethodError: undefined method `paginate' for #<Array:0x007fc580f22220>>
Any idea on how to fix this? I'm using: rails (5.1.4) and the latest versions of all said gems.
@TKB21 Try following instructions in the ArgumentError message.
@ankane Tried the following:
paginate json: Cuisine.search("american", fields: [:name]).results
but ran into the error I was displaying in the original post:
#<NoMethodError: undefined method `paginate' for #<Array:0x007fc580f22220>>
Not sure if that's what you meant. Doing some further research I found the only workaround was to require will_paginate/array in my controller(s). With this in mind do you think this is problem is more geared towards will_paginate? This issue is non-existent using kaminari just as a side note.
@TKB21 Sorry, missed that. If requiring will_paginate/array fixes it, I don't think there's an issue with either project. It's just something you'll need to do.
Cool. Thanks for the clarification.
Thanks for following up with the solution. I'm sure others will find it useful.
Most helpful comment
Thanks for following up with the solution. I'm sure others will find it useful.