In my rails-api app, a user can request for products index by pagination.
So I want to provide next and previous url via paging hash as
result = @products.paginate(:page => params[:page] || 1, :per_page => params[:per_page] || 5)
paging {
:next => www.url.com?page=next&per_page=5,
:prev => www.url.com?page=prev&per_page=5,
}
result << paging
render json: result
The above data i.e. paging hash is sent as www.url.com?page=2\u0026per_page=5
Hence, when this request comes, page and per_page params aren't recognised.
How do I resolve this??
The problem here was
render json: result
.json method
was converting the&
symbol. So I had to add following line inapplication.rb
fileFound the solution here.