Recall & Review
beginner
What is a partial template in Rails?
A partial template is a small reusable view file that helps you break down complex views into simpler pieces. It usually starts with an underscore (_) and can be included in other views.
Click to reveal answer
beginner
How do you render a partial template in a Rails view?
You use the
render method with the partial's name, like <%= render 'partial_name' %>. Rails looks for a file named _partial_name.html.erb.Click to reveal answer
intermediate
How can you pass local variables to a partial in Rails?
You pass a hash with
locals option like <%= render 'partial_name', locals: { user: @user } %>. Inside the partial, you can use user directly.Click to reveal answer
beginner
Why use partial templates in Rails?
Partial templates help keep your code DRY (Don't Repeat Yourself), make views easier to read, and allow reuse of common UI parts like headers, footers, or forms.
Click to reveal answer
beginner
What is the naming convention for partial templates in Rails?
Partial template files start with an underscore (_) followed by the name, for example,
_form.html.erb. This tells Rails it is a partial and not a full view.Click to reveal answer
How do you include a partial named '_menu.html.erb' in a Rails view?
✗ Incorrect
Use
render 'menu' to include the partial named '_menu.html.erb'.What prefix does a Rails partial template file name have?
✗ Incorrect
Partial templates start with an underscore (_) to distinguish them from full views.
How do you pass a local variable named 'item' to a partial?
✗ Incorrect
You pass locals as a hash:
render 'partial', locals: { item: item }.What is a main benefit of using partial templates?
✗ Incorrect
Partials help reuse and organize view code, making it cleaner and easier to maintain.
If you have a partial '_form.html.erb', how do you render it inside a view?
✗ Incorrect
You can render a partial by
render 'form' or render partial: 'form'.Explain what a partial template is in Rails and why you would use it.
Think about breaking big views into smaller pieces.
You got /5 concepts.
Describe how to pass data to a partial template and how to access it inside the partial.
Passing variables is like giving a friend info to use in their part.
You got /3 concepts.