If you have been working through the Hartl tutorial, you probably already have created and incorporated partials. If not, it is probably time to look through your views and do some refactoring to reduce redundancy.
Review your code, particularly any of your views (in /app/views) that may have sections of HTML which are repeated on all, or even several pages. Most commonly, your header and footer (and possibly navigation bar, if it is separate from the header) are the same on every page of a website. If you have code that compensates for older browsers or checks to see if the page should be formatted for printing, these code fragments can also be removed from their appearance on every page and tucked into a common partial file that is rendered in views/layouts/application.html.erb.
Even if you have code that is common to several pages, you can pull it out of individual files to create a partial template and then have it file called where it is needed.
- Hartl 5.1.3 on partials
- SaaS book section 5.1
- Using Partials Edge Guide to Ruby on Rails
What to Do
- Review your views for code that is common to many, if not all, files. The Hartl tutorial can walk you through creating header and footer partial templates, if you haven’t done that already. If you’ve done those steps while following along with the tutorial for other homework assignments, congratulations!! But also take a moment to review your files, looking for views that you could refactor.
- Create new partial templates, as appropriate, and call/render them from the original files … or the master layout file: views/layouts/application.html.erb if they belong on every page (remember to cut out the duplicate code).
- Rerun your test suite and fix any errors you may have introduced
What to Hand In
- Similar to prior homework assignments, submit a document that contains links to your GitHub repo (showing a new commit with “HW11” as part of the commit message)
- In the same document, include the link to the Heroku app.
- Describe what code you refactored. If you were ahead of the game and found nothing to DRY out, go ahead and tell me that.
Scoring Rubric (7 points)
- Assignment includes link to the GitHub repo
- Assignment includes link to the Heroku app.
- Described what code, if any, was refactored.
- Consistent header/navigation for the site
- Consistent footer for the site
- There are partials files in the views directory on the GitHub rep
- The partials are used in one or more pages