简体   繁体   中英

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

I'm using pagination on our Ruby on Rails app and the pages are defined in the request with a query string parameter like

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

I use this on our front page where there's no page number explicitly defined.

I'd like to do a check to see if there is a query string, and if not then display the correct page=1, by redirecting to that page I presume

Does anyone know how I can do this?

Thanks ahead for any help

Simply check,

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

Thats it ! Cheers!!!!

if params[:page].blank?
  redirect_to :page => 1
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM