使用“ude”而不是“localhost”导致域的Rails路径

时间:2017-03-07 17:23:42

标签: ruby-on-rails path

由于某种原因,当我测试时,我的所有路径和链接都会导致“ude”域而不是通常的localhost。我应该从哪里开始挖掘这个问题?

3 个答案:

答案 0 :(得分:8)

您是否可以检查 environments / test.rb,环境/开发,并确保将以下内容设置为您想要的网址:

Rails.application.routes.default_url_options[:host] = 'DESIRED URL'

答案 1 :(得分:4)

您可以在终端中使用以下命令更改域名

sudo nano /etc/hosts

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
192.168.56.2   qruqsp.local









                               [ Read 10 lines ]
^G Get Help  ^O WriteOut  ^R Read File ^Y Prev Page ^K Cut Text  ^C Cur Pos
^X Exit      ^J Justify   ^W Where Is  ^V Next Page ^U UnCut Text^T To Spell

在您的情况下将127.0.0.1更改为localhost而不是ude

使用sudo dscacheutil -flushcache

刷新DNS设置

现在rails server现在可以使用http://localhost:3000/

您也可以将其更改为您喜欢的任何内容,例如

127.0.0.1 www.rubyrails.com

中添加一行

并使用sudo dscacheutil -flushcache

刷新DNS设置

现在rails server将在http://www.rubyrails.com:3000/

中运行

答案 2 :(得分:1)

使用以_path(相对)结尾的url助手而不是_url(绝对)

相关问题