Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8557433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:34:17+00:00 2026-06-11T15:34:17+00:00

I am building a simple service(API) that will return json reponse of users objects

  • 0

I am building a simple service(API) that will return json reponse of users objects using Ruby on Rails. Since it returns an array of objects i want to add pagination functionality (:next_page , :prev) as follows.

"nextpage":www.domain.com/users?page=2&per_page=5

Currently i have a restful route that return url www.domain.com/users.How do i reconstruct the url in my index action and how do i make use of limit and offset in this case to make the pagination to work? I want to return 5 items in every page.Sorry i know it is a newbie question, it is my first time creating a service, if somebody could show me how to do the nextpage i would appreciate and i will implement prev by myself. I have tried looking for tutorials to do this but all of them they don’t show the logic in the action/method.Thank you
Note: I dont want to use will_paginate, i just need to build simple paginate

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:34:18+00:00Added an answer on June 11, 2026 at 3:34 pm

    Just append your page and page_per to your links to whatever action. Assume you have standard restful resource based routing, i.e.

    config/routes.rb:

    resources :users
    

    so you’d have the following route generated

    GET ‘/users’ => ‘users#index’

    if you send this url to your rails app:

    ‘/users?page=2&per_page=5’

    You will still get the index action, but you’ll have two extra parameters , you can do this:

    controllers/users_controller.rb

    def index
      if params[:page]
         # do your custom pagination
      else
         @users = User.all
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a simple WCF service that has to return some data from
I am building a web service API, using JSON as the data language. Designing
I'm building a VERY simple web hosting service that will cater to the ma
I'm building a new API for an existing service. The methods in it will
I'm building a web service using Flask and I'm trying to deploy a simple
I'm building a web app which will have an api and an authorization service
For a simple API I am building I am using a couple of techniques.
I'm building a simple RESTFul Service; and for achieve that I need two tasks:
I'm building a simple web application in tornado.web using mongodb as the backend. 90%
I'm building a simple search table (eventually using jquery Datatables) for our knowledgebase. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.