Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 编写一条不包含';不接受get查询参数_Ruby On Rails 3_Routes - Fatal编程技术网

Ruby on rails 3 编写一条不包含';不接受get查询参数

Ruby on rails 3 编写一条不包含';不接受get查询参数,ruby-on-rails-3,routes,Ruby On Rails 3,Routes,我想匹配一个特定的路由,但不想将该路由与任何get查询参数匹配 假设我有一条这样的路线: get'/home',to:'home#home 这对/home非常有效,但是如何输入404/home?foo=bar?如果?foo=bar在你的应用程序中毫无意义,它将毫无效果 访问/home?foo=bar将结束访问/home。这真是一个惯例。你为什么需要404?如果在你的应用程序中foo=bar毫无意义,它将毫无效果 访问/home?foo=bar将结束访问/home。这真是一个惯例。为什么需要404

我想匹配一个特定的路由,但不想将该路由与任何get查询参数匹配

假设我有一条这样的路线:

get'/home',to:'home#home


这对
/home
非常有效,但是如何输入404
/home?foo=bar

如果
?foo=bar
在你的应用程序中毫无意义,它将毫无效果


访问
/home?foo=bar
将结束访问
/home
。这真是一个惯例。你为什么需要404?

如果在你的应用程序中foo=bar毫无意义,它将毫无效果


访问
/home?foo=bar
将结束访问
/home
。这真是一个惯例。为什么需要404?

您可以使用高级约束来完成此操作。


您可以使用高级约束执行此操作。


这个问题有没有办法重新措辞?这个问题有没有办法重新措辞?
class NoQueryParamsConstraint
  def matches?(request)
    request.query_parameters.blank?
  end
end


get "/home", to: 'home#home', constraints: NoQueryParamsConstraint.new