0
0
Ruby on Railsframework~5 mins

Partial templates in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A<%= partial 'menu' %>
B<%= include 'menu' %>
C<%= render 'menu' %>
D<%= import 'menu' %>
What prefix does a Rails partial template file name have?
ANo prefix
BDot (.)
CDash (-)
DUnderscore (_)
How do you pass a local variable named 'item' to a partial?
A<%= render 'partial', locals: { item: item } %>
B<%= render 'partial', item %>
C<%= render 'partial', with: item %>
D<%= render 'partial', locals: item %>
What is a main benefit of using partial templates?
AThey speed up database queries
BThey help reuse view code and keep it organized
CThey replace controllers
DThey automatically style your page
If you have a partial '_form.html.erb', how do you render it inside a view?
ABoth A and C
B<%= render '_form' %>
C<%= render partial: 'form' %>
D<%= render '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.