Skip to content

Example code producing division by 0 error #48

@xhs345

Description

@xhs345

Expected Behavior

No error when using the example code

Actual Behavior

Getting error FloatDomainError: Infinity when using example code for jsonapi_page_size

Steps to Reproduce the Problem

Include code

  def jsonapi_page_size(pagination_params)
    per_page = pagination_params[:size].to_f.to_i
    per_page = 30 if per_page > 30
    per_page
  end

and don't provide size in the params. Method jsonapi_pagination_params will return limit 0 and jsonapi_pagination_meta will divide by it's value of 0, causing the error.

Fixed it for me by updating the code to per_page = 30 if per_page > 30 || per_page === 0

Specifications

  • Version: 1.7.0
  • Ruby version: 2.5.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions