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

非 Y 不嫁゛ 提交于 2019-12-10 16:59:41

问题


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


回答1:


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



回答2:


Simply check,

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

Thats it ! Cheers!!!!



来源:https://stackoverflow.com/questions/6888946/how-can-i-check-if-there-is-a-query-string-from-a-ruby-on-rails-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!