Project Challenge: Partials
Tidy up your "show" view by using partials.
We'll cover the following
Problem statement
In this challenge, you have to create a form partial for your comments to declutter the links/show.html.erb
file.
Important concepts
- Partials contain blocks of code that can be used in different parts of the application without needing to rewrite the code.
- For a form partial in your CRUD application, you created a new file called
app/views/pets/_form.html.erb
. - This partial could be rendered in any of the other views by using
<%= render 'form' %>
. - Since you want to render a
comments
partial for alinks
view, you will userender 'comments/form'
. Rails will figure out that you mean to render_form.html.erb
in theapp/views/comments
directory.
Implementation
Get hands-on with 1200+ tech skills courses.