Locked lesson.
About this lesson
Changing which Pins appear first and adding a new root route.
Exercise files
Download this lesson’s related exercise files.
Changing Pin Order and Adding Root.docx59.2 KB Changing Pin Order and Adding Root - Solution.docx
59.7 KB
Quick reference
Changing Pin Order and Adding Root
In this video we'll change the order of our pins and make our pins index page our root route.
When to use
We want to show the latest pins first and make our pins index page our app's root route.
Instructions
First: To make our pins index page our root route, change the root route in our config/routes.rb file to this:
root 'pins#index'
Next: To change the order of our pins, add this code to our app/controllers/pins_controller.rb file
def index
@pins = Pin.all.order("created_at DESC")
end
Next: Remove turbolinks from your app/assets/javascript/application.js file by removing the = sign:
// require turbolinks
Next: Add the jumbotron to our app/views/pins/index.html.erb file but only if a user is logged out:
<%= render 'home/jumbotron' unless user_signed_in? %>
Hints & tips
- Making our pins index page the root page is easy, just modify routes.rb
- To change the order of pins, make a small change to the pins_controller.rb file
- Remove the = sign from the turbolinks reference in application.js to fix a styling conflict
- Add the Jumbotron to our pins index page if a user is not logged in
Lesson notes are only available for subscribers.