I didn’t see this mentioned anywhere in the Rails Guide or in my admittedly cursory Google searches, but apparently it’s possible to create named redirect routes in Rails 3. For example:
Myapplication::Application.routes.draw do match "/facebook" => redirect("http://www.facebook.com/pages/MarkZuckerbergFanClub/12345678"), :as => 'facebook' match "/twitter" => redirect("http://twitter.com/TweetyMcTweet"), :as => 'twitter' end
Then you can use those in your layouts like so:
<ul class="social-links"> <li class="facebook"><%= link_to "Like us on Facebook", facebook_path %></li> <li class="twitter"><%= link_to "Follow us on Twitter", twitter_path %></li> </ul>
This entry was posted by Chris Bloom on June 13, 2011 at 11:39 pm, and is filed under Code Snippets. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site.
This site uses Akismet to reduce spam. Learn how your comment data is processed.
I’m a father, vegetarian, humanist, and software developer, living in Southwest Florida. Learn more…
Leave a Reply