Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NameError uninitialized constant JobsController::Pagination using no gems in Ruby

Using Rails 6.1.6 and Rails 2.7.0. and am following an article for adding pagination in Ruby using no gems. I’m running into a NameError exception for my Pagination module. Not certain if the naming of the hierarchy in the module is incorrect.

Pagination Helper

module PaginationHelper
  def paginate(collection:, params: {})
    pagination = Services::Pagination.new(collection, params)

    [
      pagination.metadata,
      pagination.results
    ]
  end
end

Jobs Controller

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class JobsController < ApplicationController

  include Pagination

  JOBS_PER_PAGE = 8

  def index
    @pagination, @jobs = paginate(collection: Job.all, params: page_params)
  end

Error Message
NameError Exception

I’ve tried restarting the server to no avail. Am I missing something in the Pagination module?

>Solution :

That should be include PaginationHelper in your controller.

Or rename the helper to module Pagination.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading