Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 redirect blocks with arity of 1 are deprecated

In a Rails 3.2.11 app I have the following routes in order to redirect 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

Anyway rspec throws 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 wasn't able to find something on google so I thought to ask if anybody knows how I can get rid of this warning.

Thanks

like image 625
Vassilis Avatar asked Jan 28 '13 23:01

Vassilis


1 Answers

Simply take a second parameter on the redirect block, thusly:

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 some documentation of this method here

like image 97
Daniel Evans Avatar answered Oct 13 '22 09:10

Daniel Evans