# Combining partials

**URL:** <https://www.ruby-forum.com/t/combining-partials/226161>\
**Category:** Rails\
**Created:** [December 15, 2010, 6:49pm UTC](https://www.ruby-forum.com/t/combining-partials/226161 "2010-12-15T18:49:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [December 15, 2010, 6:49pm UTC](https://www.ruby-forum.com/t/combining-partials/226161/1 "2010-12-15T18:49:33Z")

</div>

Hi,

I have 3 controller/model’s (Books, Chapters, Sections) and would like  
to combine the views into one (list of the books, chapters, sections).  
Is this possible? Would I be able to use partials even if they have  
different controllers, or do I have to combine all into a single  
controller? Any help, tips, advice is appreciated. I am still a  
beginner.

DC

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [December 15, 2010, 6:53pm UTC](https://www.ruby-forum.com/t/combining-partials/226161/2 "2010-12-15T18:53:19Z")

</div>

Dave C. wrote in post #968637:

> Hi,
> 
> I have 3 controller/model’s (Books, Chapters, Sections)

What’s a controller/model? Controllers and models are separate things,  
and need not come in pairs.

> and would like  
> to combine the views into one (list of the books, chapters, sections).  
> Is this possible?

Depends on the nature of the views.

> Would I be able to use partials even if they have  
> different controllers, or do I have to combine all into a single  
> controller?

You can use partials from anywhere. app/views/shared is the usual place  
to put partials that are used with multiple controllers.

> Any help, tips, advice is appreciated. I am still a  
> beginner.
> 
> DC

## Best,

Marnen Laibow-Koser

> **[marnen.org: Homepage of Marnen Laibow-Koser](https://marnen.org/)**

[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [December 15, 2010, 9:44pm UTC](https://www.ruby-forum.com/t/combining-partials/226161/3 "2010-12-15T21:44:53Z")

</div>

On 15 December 2010 17:49, Dave C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I have 3 controller/model’s (Books, Chapters, Sections) and would like  
> to combine the views into one (list of the books, chapters, sections).  
> Is this possible? Would I be able to use partials even if they have  
> different controllers, or do I have to combine all into a single  
> controller? Any help, tips, advice is appreciated. I am still a  
> beginner.

Just assemble the data you need for the partials in whatever  
controller you deem appropriate, and in the view render the  
appropriate partials passing them the data they need. Don’t forget  
that if you have a book object @book then its chapters will be  
@book.chapters and for each chapter the sections will be  
chapter.sections (assuming you have set the associations up  
appropriately, and assuming I am interpreting your problem correctly.

Colin

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [December 19, 2010, 6:25pm UTC](https://www.ruby-forum.com/t/combining-partials/226161/4 "2010-12-19T18:25:21Z")

</div>

Colin L. wrote in post #968709:

> On 15 December 2010 17:49, Dave C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hi,
> > 
> > I have 3 controller/model’s (Books, Chapters, Sections) and would like  
> > to combine the views into one (list of the books, chapters, sections).  
> > Is this possible? Would I be able to use partials even if they have  
> > different controllers, or do I have to combine all into a single  
> > controller? Any help, tips, advice is appreciated. I am still a  
> > beginner.
> 
> Just assemble the data you need for the partials in whatever  
> controller you deem appropriate, and in the view render the  
> appropriate partials passing them the data they need. Don’t forget  
> that if you have a book object @book then its chapters will be  
> @book.chapters and for each chapter the sections will be  
> chapter.sections (assuming you have set the associations up  
> appropriately, and assuming I am interpreting your problem correctly.
> 
> Colin

Thanks for your helpful reply.

Dave
