Linking to another page in Rails – building a nav bar

By | 11/09/2015

To create a link to another page in rails you use the ‘link_to’ method and pass in the internal path of the page.

I have a view called in my static_pages folder in views, so to link to this from another view I would use:

<%= link_to (“Text you want to appear”, folder-name_view-name_path) %>

In my case it looked like this:

<%= link_to("Home", static_pages_home_path) %>

If I'm building out a nav bar this would be the following:
      <%= link_to("home", static_pages_home_path) %>
      <%= link_to("About", static_pages_about_path_path) %>

This currently sits in the layouts/application.html.erb and because it's static and unlikely to change it's best to move it to a partial, but that's another post.