💎 Ruby on Rails
Beginner
What are partials in Rails views?
Answer
Partials are reusable view fragments stored in files prefixed with an underscore (e.g., _post.html.erb). Render with <%= render 'post', post: @post %> or the shorthand <%= render @post %> (Rails infers the partial name from the model). <%= render @posts %> iterates and renders the partial for each item. Partials reduce duplication — a _form.html.erb partial can be shared between new and edit views. Local variables passed to partials are scoped to that partial only.