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.