Rails获取应用程序根目录/基本URL [英] rails get app root/base url

查看:117
本文介绍了Rails获取应用程序根目录/基本URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我有一些在api域下的API.现在,在其中一个API中,我想生成一个指向主域的网址,例如

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...

我尝试使用 url_for ,但默认的 root_url request.host 在api域中. Url_for将使其成为

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..

我希望它成为

test.com/blabla...

Url_for可以接受参数

Url_for can take a parameter

host: ...

将其设置为test.com/,问题是如何获取主机的根/基URL(test.com)? root_url request.host 都是api.test.com.

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.

有什么想法吗?谢谢.

推荐答案

根据,您可以request.domain

这篇关于Rails获取应用程序根目录/基本URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆