在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)
我无法在谷歌上找到任何东西所以我想问一下是否有人知道如何摆脱这个警告。
由于
答案 0 :(得分:5)
只需在重定向块上选择第二个参数:
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