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!
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
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).