JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

undefined method `calculate_page_count' for nil:NilClass

Open
#1,284 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

https://github.com/cerebris/jsonapi-resources/blob/41df1475876dd7cfa3459e9cf0241a82e71c59c9/lib/jsonapi/processor.rb#L89

Configuration for JSONAPI http://jsonapi-resources.com/v0.8/guide/configuration.html

JSONAPI.configure do |config|

# :none, :offset, :paged, or a custom paginator name

config.default_paginator = :paged
config.default_page_size = 10
config.maximum_page_size = 50config.top_level_meta_include_record_count = true
config.top_level_meta_record_count_key = :record_count
config.top_level_meta_include_page_count = true
config.top_level_meta_page_count_key = :page_count
end

class ContactResource < BaseResource
attributes :name, :email

paginator :none
end

When paginator is set to :none in resource level, Then it shows undefined method `calculate_page_count' for nil:NilClass

solution:
https://github.com/cerebris/jsonapi-resources/blob/41df1475876dd7cfa3459e9cf0241a82e71c59c9/lib/jsonapi/processor.rb#L89

if (paginator && JSONAPI.configuration.top_level_meta_include_page_count && record_count)
page_count = paginator.calculate_page_count(record_count)
end

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/jsonapi/processor.rb at the referenced line and reproduce the configuration with a resource using paginator :none and page-count metadata enabled. Confirm the request no longer raises undefined method `calculate_page_count' for nil:NilClass and that the response metadata remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.