1
2.3.2から2.3.11に私のレールの宝石をアップグレードしようとしています。しかし、私はwill_paginate 2.3.15にいくつかの問題があり、jsonを元に戻します。レンダリングjson with railsでwill_paginateに問題があります。2.3.11
module WillPaginateHelpers
WillPaginate::Collection.class_eval do
alias :to_json_without_paginate :to_json
def to_json(options = {})
hash = { :current_page => current_page,
:per_page => per_page,
:total_entries => total_entries,
:total_pages => total_pages,
:items => to_a
}
hash.to_json(options)
end
end
end
以前は、上記のコードがで仕事ができる:render :json => @products.to_json
:レール2.3.11で、
@products = Product.paginate(:page => 1, :per_page => 20)
render :json => @products
しかし、それは私がこの方法をコーディングする必要がない限り、エラー「オブジェクト参照そのもの」を思い付きます。 これを修正するには? render :json => @products
ではどうなりましたか?