# Partials in rails

**URL:** <https://www.ruby-forum.com/t/partials-in-rails/178599>\
**Category:** Rails\
**Created:** [November 7, 2009, 1:03pm UTC](https://www.ruby-forum.com/t/partials-in-rails/178599 "2009-11-07T13:03:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aashishkiran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@aashishkiran](https://www.ruby-forum.com/u/aashishkiran)\
**Post date:** [November 7, 2009, 1:03pm UTC](https://www.ruby-forum.com/t/partials-in-rails/178599/1 "2009-11-07T13:03:37Z")

</div>

I am new to rails. can anyone explain in detail about partials in rails.  
my rails version is 2.3.4.  
How to use them?

---

<div class="post-metadata">

**Author:** ![aashishkiran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@aashishkiran](https://www.ruby-forum.com/u/aashishkiran)\
**Post date:** [November 7, 2009, 2:37pm UTC](https://www.ruby-forum.com/t/partials-in-rails/178599/2 "2009-11-07T14:37:11Z")

</div>

On Sat, Nov 7, 2009 at 9:03 AM, Aashish K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am new to rails. can anyone explain in detail about partials in rails.  
> my rails version is 2.3.4.  
> How to use them?

Have you search something about this? I’m pretty sure this has been  
explained zillions of times before, for example, here:

> **[Layouts and Rendering in Rails — Ruby on Rails Guides](https://guides.rubyonrails.org/layouts_and_rendering.html#using-partials)**
>
> Layouts and Rendering in RailsThis guide covers the basic layout features of Action Controller and Action View.After reading this guide, you will know: How to use the various rendering methods built into Rails. How to create layouts with multiple...

–  
Leonardo M…  
There’s no place like ~

---

<div class="post-metadata">

**Author:** ![aashishkiran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@aashishkiran](https://www.ruby-forum.com/u/aashishkiran)\
**Post date:** [November 7, 2009, 10:28pm UTC](https://www.ruby-forum.com/t/partials-in-rails/178599/3 "2009-11-07T22:28:19Z")

</div>

On Sat, Nov 07, 2009 at 01:03:37PM +0100, Aashish K. wrote:

> I am new to rails. can anyone explain in detail about partials in  
> rails. my rails version is 2.3.4. How to use them?

Partials are basically “includes.” The tricky part is generally getting  
variables from the main view to propagate to the partial. This requires  
using “:locals=\>{}” properly, which doesn’t always seem to work the way  
I expect.

–  
“Oh, look: rocks!”  
– Doctor Who, “Destiny of the Daleks”

---

<div class="post-metadata">

**Author:** ![aashishkiran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@aashishkiran](https://www.ruby-forum.com/u/aashishkiran)\
**Post date:** [November 7, 2009, 10:38pm UTC](https://www.ruby-forum.com/t/partials-in-rails/178599/4 "2009-11-07T22:38:22Z")

</div>

Todd A. Jacobs wrote:

> On Sat, Nov 07, 2009 at 01:03:37PM +0100, Aashish K. wrote:
> 
> > I am new to rails. can anyone explain in detail about partials in  
> > rails. my rails version is 2.3.4. How to use them?
> 
> Partials are basically “includes.” The tricky part is generally getting  
> variables from the main view to propagate to the partial.

Not tricky at all.

> This requires  
> using “:locals=\>{}” properly, which doesn’t always seem to work the way  
> I expect.

It has always worked for me. Can you provide an actual example that  
doesn’t work?

> –  
> “Oh, look: rocks!”  
> – Doctor Who, “Destiny of the Daleks”

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![aashishkiran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@aashishkiran](https://www.ruby-forum.com/u/aashishkiran)\
**Post date:** [November 8, 2009, 9:51am UTC](https://www.ruby-forum.com/t/partials-in-rails/178599/5 "2009-11-08T09:51:37Z")

</div>

Aashish K. wrote:

> I am new to rails. can anyone explain in detail about partials in rails.  
> my rails version is 2.3.4.  
> How to use them?

You can think of partials as making function calls from your erb files  
which generates templated html for you. The values for template  
variables you can pass through local and object variables. If you want  
same set of templated html to be generated from N places in your site,  
you can create a partial and call this from all of these N places. Any  
time you want to change the code you change in one place rather than N  
places. It helps you to follow DRY principle.

Thanks  
– Prasad  
[http://roorky.com](http://roorky.com)  
Digital Interactive Publication
