Iteration F1: Moving the Cart
Currently, our cart is rendered by the show action in the CartController and the corresponding html.erb template. What we’d like to do is to move that rendering into the sidebar. This means it’ll no longer be in its own page. Instead, we’ll render it in the layout that displays the overall catalog. And that’s easy using partial templates.
Partial Templates
Programming languages let you define methods. A method is a chunk of code with a name: invoke the method by the name, and the corresponding chunk of code gets run. And, of course, you can pass parameters to a method, which lets you write a piece of code that can be used in many different circumstances.
You can think of Rails partial templates (partials for ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access