author avatar

syedsibtain

Tue May 07 2024

In Rails, a partial is a reusable view template that allows you to encapsulate a portion of a view into a separate file. Partials are useful for organising and reusing code, especially when certain components or elements are repeated across multiple views within an application.

We can create a partial by creating a new file with a name that begins with an underscore (_). For example, _sidebar.html.erb or _header.html.erb.

And to render a partial within another view, use the render method with the name of the partial file (without the underscore) as an argument. For example, <%= render 'sidebar' %> will render the _sidebar.html.erb partial within the current view.

#rails