Mark McWiggins
Mark McWiggins

Reputation: 651

Rails 4.2: redirect to remote URL fails

I have this simple Rails app I'm working on and for the moment I want to redirect to another server remote URL.

In config/routes.rb I have:

  get "/adaptapp" => redirect(path: "https://exturl.com/adaptapp")

And rake routes gives:

Prefix Verb URI Pattern              Controller#Action
 welcome_index GET  /welcome/index(.:format) welcome#index
 adaptapp GET  /adaptapp(.:format)      redirect(301, path: 
                                https://exturl.com/adaptapp)

which to me look OK. But when I try it (http://railsurl.com:3000/adaptapp) I get an error:

No route matches [GET] "/https:/exturl.com/adaptapp"

What's going on? How do I fix this?

Upvotes: 1

Views: 86

Answers (2)

Daniel
Daniel

Reputation: 899

get "/adaptapp" => redirect("https://exturl.com/adaptapp"), path param makes your url relative.

Upvotes: 0

Josh Brody
Josh Brody

Reputation: 5363

The syntax of a URI is scheme:[//[user[:password]@]host[:port]][/path][?query][#fragment]

Having said, your syntax is yielding the correct response for the code you provided. What you want is redirect("https://exturl.com/adaptapp")

Upvotes: 2

Related Questions