Rails 中带有 url_for 的完整 URL [英] Full URL with url_for in Rails
本文介绍了Rails 中带有 url_for 的完整 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 rails 中获取完整的 url?
How can I get a full url in rails?
url_for @book 只返回像/book/1 这样的路径,而不是 www.domain.com/book/1
url_for @book is returning only a path like /book/1 and not www.domain.com/book/1
谢谢(如果答案很明显,我很抱歉.我正在学习 Rails!)
Thanks (and sorry if the answer is obvious. Im learning rails!)
推荐答案
使用 :host 选项.例如,您可以使用:
Use the :host option. For example, you can use:
url_for(@book, :host => "domain.com")
注意:对于 Rails 3 及以上版本,使用 polymorphic_url
而不是 url_for
.
Note: with Rails 3 and above, use polymorphic_url
instead of url_for
.
这篇关于Rails 中带有 url_for 的完整 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文