Search code examples
ruby-on-railsruby-on-rails-3rails-routing

rails get app root/base url


In my app I have a few APIs that under api domain. Now in one of the API I want to generate a url that pointing to the main domain, say

test.com/blabla...

I tried to use url_for but seems the default root_url or request.host is in api domain. Url_for will make it to be

api.test.com/blabla..

while I want it to be

test.com/blabla...

Url_for can take a parameter

host: ...

to set it to be test.com/, the question is how can I get the root/base url (test.com) for host? root_url or request.host are all api.test.com.

Any ideas? Thanks.


Solution

  • According to this you can do request.domain