- Practice using partials.
- Use all the different techniques you've learned in this unit.
- DRY up your views with locals.
We have a Rails app that showcases some of our favorite programmers. The landing
page is an index of all of the programmers, and users can click on each
programmer to see his or her profile page. There's just one problem: the views
are loaded with repetition and clunky iteration and could use some serious
refactoring. Your job is to clean up programmers/index.html.erb
and
programmers/show.html.erb
by using partials.
Fork and clone the lab. Run bundle install
and rake db:migrate
, then rake db:migrate RAILS_ENV=test
. Next, seed the database with some programmers - run
rake db:seed
- and start the server to see the app in the browser.
Run rspec
and make the tests pass one at a time! The app will continue to have
the same functionality (keep checking it in the browser), but you'll be making
the following partials to clean up the views:
- A partial to render the navbar.
- A partial to render all of the programmers on the index page.
- Rails Guides โ Using Partials
- Action View Partials
- Metaprogramming in Ruby (see section 1.3.2 to learn about
send
) - Stack Overflow โ Passing Variables to a Partial (see the first answer for a concise example)