Geoff
Geoff

Reputation: 9590

Getting the URL of a Ruby on Rails app?

I have a helper in my Ruby on Rails app for the unsecure_url

def unsecure_url
  "http://localhost:3000/"
end

However, this is wrong when it the app is live. I just put the app online and would like to do something like this:

def unsecure_url
  if is_production
    production_url # <-- any way to determine this dynamically?
  else
    "http://localhost:3000/"
  end
end

Any advice on how to do this?

Upvotes: 1

Views: 2671

Answers (2)

Chris Doyle
Chris Doyle

Reputation: 1039

If you don't need the full path you could use root_url. That'll give you the http://localhost:3000/ part. If you want any path info like /blogs/123 you'll need the request methods already mentioned.

Upvotes: 1

KMC
KMC

Reputation: 20036

My understanding is you just want to get the URl of the current page?

def unsecure_url
  if is_production
    production_url = request.request_uri
  else
    "http://localhost:3000/"
  end
end

Upvotes: 0

Related Questions