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 RESTful Design which creates seven routes all mapping to the user controller. Rails also allows you to define multiple resources in one line.
Rails routing is a two-way piece of machinery – rather as if you could turn trees into paper, and then turn paper back into trees. Specifically, it both connects incoming HTTP requests to the code in your application's controllers, and helps you generate URLs without having to hard-code them as strings.
I know this is old, so in case someone else needs this for rails 4:
get "/blog" => redirect("http://example.com/blog")
Use get instead of Match in Rails 4, otherwise you'll get a Runtime error
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With