如何检查是否有来自 Ruby on Rails 控制器的查询字符串? [英] How can I check if there is a query string from a Ruby on Rails controller?

查看:34
本文介绍了如何检查是否有来自 Ruby on Rails 控制器的查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我们的 Ruby on Rails 应用程序上使用分页,页面在请求中使用查询字符串参数定义,如

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.

我想检查一下是否有查询字符串,如果没有,则通过重定向到我认为的那个页面来显示正确的 page=1

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?

提前感谢您的帮助

推荐答案

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

这篇关于如何检查是否有来自 Ruby on Rails 控制器的查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆