[英]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 我在Ruby on Rails应用程序上使用分页,并在请求中使用查询字符串参数定义页面
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 我想检查是否有查询字符串,如果没有,则显示正确的页面= 1,通过重定向到我认为的页面
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.