加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 不推荐使用arity为1的Rails 3重定向块

发布时间:2020-12-17 03:15:45 所属栏目:百科 来源:网络整理
导读:在Rails 3.2.11应用程序中,我有以下路由,以便将www重定向到非www: constraints(:host = /www.foo.com/) do root :to = redirect("http://foo.com") match '/*path',:to = redirect {|params| "http://foo.com/#{params[:path]}"}end 无论如何,rspec会抛出以
在Rails 3.2.11应用程序中,我有以下路由,以便将www重定向到非www:

constraints(:host => /www.foo.com/) do
    root :to => redirect("http://foo.com")
    match '/*path',:to => redirect {|params| "http://foo.com/#{params[:path]}"}
end

无论如何,rspec会抛出以下警告:

DEPRECATION WARNING: redirect blocks with arity of 1 are deprecated. Your block must take 2 parameters: the environment,and a request object. (called from block (2 levels) in <top (required)> at /foo/config/routes.rb:6)

我无法在谷歌上找到一些东西所以我想问是否有人知道如何摆脱这个警告.

谢谢

解决方法

只需在重定向块上获取第二个参数,即:

constraints(:host => /www.foo.com/) do
  root :to => redirect("http://foo.com")
  match '/*path',:to => redirect {|params,request| "http://foo.com/#{params[:path]}"}
end

您可以看到此方法here的一些文档

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读