In this lesson we're going to be creating a privacy and terms pages and linking to them in our new footer partial. To accomplish this we'll start with the rails generate command. We're going to type the following command in our terminal:
rails g controller Home index privacy terms
We've actually already ran
rails g controller Home index
but Rails is smart enough to keep sort the new from the old and ask us want we want to overwrite or not. In my case it asked about index.html.erb first, which we don't want to overwrite, followed by the home_controller_test.rb which we do want to overwrite. Finally, we don't want to overwrite the CSS file either.
Now our HomeController has the terms and privacy actions in it and they been declared in routes.rb as well. The default declaration doesn't offer us the route helper method so let's refactor the routes a bit.
get 'privacy', to: 'home#privacy', as: 'privacy' get 'terms', to: 'home#terms', as: 'terms'
Remember the as: 'privacy' and as: 'terms' sections of each line gives us access to the helper method to link to this path in our application. So let's hop over to our footer and link to these pages. We're only going to be using one of the 4 div tags that defined column usage in the footer so let's comment out the other 3. Inside of the remaining div tag let's replace the h5 tag's Column 1 text with something like Site information and also create a ul element with a couple of li tags in it. The li tags will house our links to the new routes.
<div class="col-sm-12 col-md-3 mt-5"> <h5>Site information</h5> <ul> <li> <%= link_to 'Privacy', privacy_path %> </li> <li> <%= link_to 'Terms and Conditions', terms_path %> </li> </ul> </div>
Now we have an ugly footer that links to a couple of ugly pages. That's okay, though! We'll work on styling everything soon.