Rails4 and “undefined local variable or method `root_path'”

I recently started to mess around with Rails again and wanted to see what’s up with Rails4. I created my project using composer ( using bootstrap,haml,rails4 ) and created a simple scaffold.

When I fired up the rails server and tried to visit my scaffold page I got the following error: “undefined local variable or method `root_path'”. The error was in one of the layout templates where it referenced the root_path. I googled around a bit for the specific error with no luck. Then tried the search “rails4 root_path”. Seems like its no longer defined as a route by default. You have to do the following to get it to work:

  1. Open routes.rb
  2. add a route like the following
  3. root :to => "controller#action"

Hope this helps others!

1 thought on “Rails4 and “undefined local variable or method `root_path'””

Leave a Reply

Your email address will not be published. Required fields are marked *