How to check if there is a query string from a Ruby on Rails controller?

I use pagination in our Ruby on Rails application, and the pages are defined in the request with a query string parameter like

http://ourdomain.com/?page=2 

I use this on our first page, where the page number is not explicitly specified.

I would like to do a check to see if there is a query string, and if not, then display the correct page = 1, redirecting it to this page, I assume

Does anyone know how I can do this?

Thanks for any help

+4
source share
2 answers
 if params[:page].blank? redirect_to :page => 1 end 
+7
source

Just check

 if request.query_string.present? # Do your stuff here. end 

Here it is! Hooray!!!!

+10
source

All Articles