开发者

Getting the URL of a Ruby on Rails app?

I have a helper in my Ruby开发者_StackOverflow社区 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?


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜