Routes in Rails

By | 11/09/2015

A couple of posts back I created my nav menu by linking to other pages in my site using the link_to method.  I then moved the whole chunk of code into a partial and used the render method to show it in the main view.

I now want my url structure to look a little neater, instead of showing /static_pages/home it would be great if it just said /home.
This is where Rails Routes comes in.

Head over to your routes.rb file in the config directory.

first off you’ll want to set your root director to home so use the following command:

root “static_pages#home”
Or whatever he name of your controller is and then the page after the #.

Then I changed my structure so it all looked like the following:

get "blog" => "static_pages#blog"

This way when someone types in /blog that's what remains.