{"id":106,"date":"2014-01-04T14:34:39","date_gmt":"2014-01-04T19:34:39","guid":{"rendered":"http:\/\/themayesfamily.com\/blogs\/b\/?p=106"},"modified":"2014-01-04T14:34:39","modified_gmt":"2014-01-04T19:34:39","slug":"rails4-and-undefined-local-variable-or-method-root_path","status":"publish","type":"post","link":"https:\/\/themayesfamily.com\/blogs\/b\/2014\/01\/04\/rails4-and-undefined-local-variable-or-method-root_path\/","title":{"rendered":"Rails4 and &#8220;undefined local variable or method `root_path'&#8221;"},"content":{"rendered":"<p>I recently started to mess around with Rails again and wanted to see what&#8217;s up with Rails4.  I created my project using <a href=\"http:\/\/railsapps.github.io\/rails-composer\/\">composer<\/a> ( using bootstrap,haml,rails4 ) and created a simple <a href=\"http:\/\/guides.rubyonrails.org\/command_line.html\">scaffold<\/a>.<\/p>\n<p>When I fired up the rails server and tried to visit my scaffold page I got the following error: &#8220;undefined local variable or method `root_path'&#8221;.  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 &#8220;rails4 root_path&#8221;.  Seems like its no longer defined as a route by default.  You have to do the following to get it to work:<\/p>\n<ol>\n<li>Open routes.rb<\/li>\n<li>add a route like the following<\/li>\n<p><code>root :to => \"controller#action\"<\/code>\n<\/ol>\n<p>Hope this helps others!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently started to mess around with Rails again and wanted to see what&#8217;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: &#8220;undefined local variable or &hellip; <a href=\"https:\/\/themayesfamily.com\/blogs\/b\/2014\/01\/04\/rails4-and-undefined-local-variable-or-method-root_path\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Rails4 and &#8220;undefined local variable or method `root_path&#8217;&#8221;&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[24,28,45,46,48],"class_list":["post-106","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-code","tag-error","tag-rails","tag-rails4","tag-ruby"],"_links":{"self":[{"href":"https:\/\/themayesfamily.com\/blogs\/b\/wp-json\/wp\/v2\/posts\/106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themayesfamily.com\/blogs\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themayesfamily.com\/blogs\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themayesfamily.com\/blogs\/b\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/themayesfamily.com\/blogs\/b\/wp-json\/wp\/v2\/comments?post=106"}],"version-history":[{"count":0,"href":"https:\/\/themayesfamily.com\/blogs\/b\/wp-json\/wp\/v2\/posts\/106\/revisions"}],"wp:attachment":[{"href":"https:\/\/themayesfamily.com\/blogs\/b\/wp-json\/wp\/v2\/media?parent=106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themayesfamily.com\/blogs\/b\/wp-json\/wp\/v2\/categories?post=106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themayesfamily.com\/blogs\/b\/wp-json\/wp\/v2\/tags?post=106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}