Mostly programming and parenting, and not a hint of sarcasm
Posts tagged ruby
Named redirect routes in Rails 3
0254 days
by Chris Bloom
in Code Snippets
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'endThen 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>
Recent Comments