我正在使用Sorcery进行身份验证,并且需要在其初始化程序中设置第三方身份验证.
I'm using Sorcery for Authentication, and I need to setup third party authentication in its initializer.
初始化程序的一行看起来像这样:
The initializer has a line that looks like this:
config.twitter.callback_url "example.dev/auth/callback?provider=twitter"...其中,当我在本地开发中使用Pow时,其中example.dev是主机名.如果应用程序正在生产中,则必须为example;如果应用程序正在生产中,则必须为staging.example.
...where example.dev is the hostname when I'm using Pow in local development. This needs to be example if the app is in production, or staging.example if it's in staging, etc.
我想将此行设置为类似这样的内容:
I would like to set this line to be something like this:
config.twitter.callback_url "#{Rails.hostname}/auth/callback?provider=twitter"...但是request.host是我所知道的唯一方法,它知道这一点,并且仅在控制器级别可用.
... but request.host is the only method I know of that knows that and it's only available at the controller level.
我可以使用条件测试并为每个环境手动设置主机名,但是当我在不同的本地和暂存环境中进行测试时,能够以编程方式设置此设置将是很棒的选择.
I can use a conditional test and manually setup a hostname for each environment, but as I test on different local and staging environments it would be great to just be able to set this programatically.
有什么建议吗?
推荐答案使用:
`hostname`它使用Unix的主机名"实用程序,并返回一个字符串.
That uses the Unix "hostname" utility, and it returns a string.
更多推荐
Rails:在初始化程序中获取主机名
发布评论