Relational 3 redirection units with arity 1 are deprecated

In Rails 3.2.11 application, I have the following routes for redirecting www to non-www:

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

In any case, rspec displays the following warning:

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)

I was not able to find something on Google, so I thought to ask if anyone knows how I can get rid of this warning.

thank

+5
source share
1 answer

Just take the second parameter in the redirect block like this:

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

You can see the documentation for this method here

+5
source

All Articles