Adding a Static About Page in Rails
I’ve been building the Narify application based on a user that hasn’t logged into the system, i.e. unauthenticated. The Ruby on Rails people in my life have informed me that there’s this nifty Devise apparatus for handling user authentication. Looking forward, I’ll want to have the following in my routes.rb
file:
Which for me at this point in the app’s infancy, means I’ll need a HomeController, home folder for views, and the following in my routes file:
So let’s make this happen. We’ll refactor (change our code) at a later date once we decide to have authenticated users. And I’m pretty sure we’ll need to refactor the root to:
narrations as the home page. Eventually we’ll want that as a page-within-a-page. Maybe I’ll do that next, but first let’s create that controller to correspond to my new ‘about’ route.
And now I need a Haml view to render, so let’s create app/views/home/about.html.haml
:
And testing localhost:3000/about
successfully renders the about page, so the last bit I want to do is create a link on my Narrations home page to take me to the About page. Here’s my updated home.html.haml
file:
Nothing fancy, just a secondary heading between the primary heading and my narrations list.
Even though this Rails app is extremely rudimentary, I can understand the need for tests and proper organization. I’m already thinking I’ll need to refactor my code and folder/file structure. I think I’ll do that next.