创建到外部 URL 的 rails 路由 [英] Creating a rails route to an external URL

查看:14
本文介绍了创建到外部 URL 的 rails 路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的很多用户一直访问 http://(rails app URL)/blog,但我实际上没有博客.我终于建立了一个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.

Rails 3

# in routes.rb
match "/blog" => redirect("http://example.com/blog"), :as => :blog

Rails 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆