如何设置 root_url [英] How to set root_url
问题描述
在我的 Ruby on Rails 3.1 应用程序中,我有一个这样的链接:
In my Ruby on Rails 3.1 app I have a link like this:
<%= link_to 'Home', root_url %>
在我的开发中.机器它呈现一个带有localhost:3000"的链接.在生产中,它会呈现一个带有 IP 地址的链接,例如83.112.12.27:8080".我想强制 rails 呈现域地址而不是 IP 地址.如何设置 root_url?
On My dev. machine it renders a link with "localhost:3000". On production it renders a link with an IP Address like this "83.112.12.27:8080". I would like to force rails to render the domain address instead of the IP Address. How can I set root_url?
推荐答案
在你的路线集中:
root :to => 'welcome#index'
并在您的链接集中:
<%=link_to "Home", root_path %>
它会渲染
<a href="/">Home</a>
所以在你的本地主机中它会带你去
So in your localhost It'd take you to
http://localhost:3000/
在您的生产服务器中它会带您到
and in your production server It'd take you to
http://yourdomian.com/
和routes.rb
将默认呈现控制器welcome
的index
动作.
and the routes.rb
will render the index
action of the controller welcome
by default.
附注.您还需要从 public
目录中删除 index.html
才能使用它.
PS. you also need to remove index.html
from public
directory in order to use this.
更新
关于路由的更多信息:
这篇关于如何设置 root_url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!