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 4063672
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:45:22+00:00 2026-05-20T15:45:22+00:00

Hey. I am using the following line over and over in my controller index

  • 0

Hey. I am using the following line over and over in my controller index queries. Does it makes sense to create a new application method to re-use it? Any suggestions on how I could extract this and perhaps pass the :per_page attribute a variable parameter?

paginate :page => params[:page], :per_page => 12

Thanks for your time!

  • 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-05-20T15:45:23+00:00Added an answer on May 20, 2026 at 3:45 pm

    You could definitely do this in your application controller. I think since it’s a one-liner, you’re saving very little in terms of keystrokes and text. Still, if you wanted to do it, you could put something like this in application_controller.rb file

    # optional-- this lets you use the method in views as well
    helper_method :paginate_helper
    
    ...
    # optional, but safer
    protected
    
    def paginate_helper(obj_to_paginate, page_limit)
      obj_to_paginate.paginate :page => params[:page], :per_page => page_limit
    end
    

    depending on the scope that you’ll use this helper in, you may want to add an if statement regarding params[:page]. paginate will work with :page=> nil, however you could get an error for params[] if params doesn’t exist (i.e. you’d be doing nil[], trying to treat nil like an array).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey I am currently using the following code Dim flickr As New Flickr(apikey) Dim
Hey everyone, I need to convert the following format into a new format using
Hey everyone. The following is the code that I am using to play random
Hey i'm using oracle sql to create a database. I im now working on
Hey so I am using Rails PJAX for my web application with twitter bootstrap
Hey everyone, I have achieved the effect described in the title using the following
Hey I have the following code which I'm using to isolate the a b
Hey guys..I am designing a set-up wizard using CPropertySheet and CpropertyPage in MFC application...I
Hey guys, I'm writing a Firefox plugin and using the following function: var obj
Hey there guys and gals. I'm very new to php and am following various

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.