创建到外部URL的Rails路线 [英] Creating a rails route to an external URL
本文介绍了创建到外部URL的Rails路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的许多用户都继续访问 http://(rails应用程序URL)/博客
,但实际上我没有博客。我终于建立了一个Posterous博客,现在想将我的用户定向到那里。有没有一种方法可以使用routes.rb进行配置?有没有比编辑httpd.conf文件更好的方法了?
A lot of my users keep going to http://(rails app URL)/blog
, but I don't actually have a blog. I finally setup a Posterous blog and now want to direct my users there. Is there a way to configure this using routes.rb? Is there a better way that doesn't involve editing the httpd.conf file?
推荐答案
取决于您使用的Rails版本。
Depends on the Rails version you are using.
路轨3
# in routes.rb
match "/blog" => redirect("http://example.com/blog"), :as => :blog
路轨2
# in routes.rb
map.blog '/blog',
:controller => "a_helper_controller",
:action => "redirect_to_blog"
# in a_helper_controller.rb
def redirect_to_blog
redirect_to "http://example.com/blog"
end
这篇关于创建到外部URL的Rails路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文