Wednesday, May 25, 2011

Setting a home directory link in Rails 3

If you need to set up a path to the home directory in Rails 3  you need to change your routes.rb  file to create a named path.  In your routes.rb file you create the following mapping

match '/' => "home#index", :as => :home

this assumes your rails app has been created with 

rails generate controller home index


you can then create a link using linked_to

<%= link_to "Home", home_path %>

The point here is we've created the named link as "home"  but the path is referred to home_path.


  1. interesting blog. It would be great if you can provide more details about it. Thanks you

    Web Development

  2. Thanks for this coding post. I will try it and have already
    bookmarked your blog
    custom Web Design

  3. Thanks for this simple solution on creating a link back to the home page - i was stuck for 30 mins and no other post gave a solution that worked for me.