0
我正在使用api-pagination
gem並在rails 5應用程序中部署到heroku。我的配置在開發中沒問題,但在生產中失敗。下面是配置文件:Rails 5中api-pagination gem配置錯誤部署到heroku時
config/initializers/api_pagination.rb
ApiPagination.configure do |config|
# If you have both gems included, you can choose a paginator.
config.paginator = :will_paginate
# By default, this is set to 'Total'
config.total_header = 'X-Total'
# By default, this is set to 'Per-Page'
#config.per_page_header = 'X-Per-Page'
# Optional: set this to add a header with the current page number.
#config.page_header = 'X-Page'
# Optional: what parameter should be used to set the page option
config.page_param = :page
# or
config.page_param do |params|
params[:page][:number]
end
# Optional: what parameter should be used to set the per page option
config.per_page_param = :per_page
# or
config.per_page_param do |params|
params[:page][:size]
end
end
這裏從Heroku的日誌中的錯誤:
[INFO ] Completed 500 Internal Server Error in 1ms (ActiveRecord: 0.0ms)
[FATAL] NoMethodError (undefined method `[]' for nil:NilClass):
[FATAL] config/initializers/api_pagination.rb:18:in `block (2 levels) in <top (required)>'
控制器動作很簡單,現在:
def index
listings = Listing.where(active: true)
paginate json: listings
end
我在路線中沒有包含任何參數。