# Render partial questions

**URL:** <https://www.ruby-forum.com/t/render-partial-questions/98254>\
**Category:** Rails\
**Created:** [July 13, 2006, 3:10pm UTC](https://www.ruby-forum.com/t/render-partial-questions/98254 "2006-07-13T15:10:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![subroutine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@subroutine](https://www.ruby-forum.com/u/subroutine)\
**Post date:** [July 13, 2006, 3:10pm UTC](https://www.ruby-forum.com/t/render-partial-questions/98254/1 "2006-07-13T15:10:29Z")

</div>

Hello,

what is the preferred way to do this…

I have 2 controllers. Each has an index action.  
Now I want to include the rendered index view from TwoController in the  
index view of OneController.

But a render :partial doesn’t execute the TwoController index action  
which sets variables for its index view.

So maybe you can give me a short example how to do it.

Thank you  
Markus

---

<div class="post-metadata">

**Author:** ![subroutine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@subroutine](https://www.ruby-forum.com/u/subroutine)\
**Post date:** [July 13, 2006, 3:27pm UTC](https://www.ruby-forum.com/t/render-partial-questions/98254/2 "2006-07-13T15:27:04Z")

</div>

See render\_component

---

<div class="post-metadata">

**Author:** ![subroutine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@subroutine](https://www.ruby-forum.com/u/subroutine)\
**Post date:** [July 13, 2006, 3:34pm UTC](https://www.ruby-forum.com/t/render-partial-questions/98254/3 "2006-07-13T15:34:05Z")

</div>

> But a render :partial doesn’t execute the TwoController index action  
> which sets variables for its index view

Try this:

We have a orders controller and a people controller with a partial in  
people:

render(:partial =\> ‘people/my\_partial’)

If there is a slash, rails will use app/views/ as the base rather than  
the current controller’s directory.

I wouldn’t recommend using components (also suggested) as they’re  
notoriously in-efficient and there is word of them being phased out…

Hope that helps,

Steve

---

<div class="post-metadata">

**Author:** ![subroutine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@subroutine](https://www.ruby-forum.com/u/subroutine)\
**Post date:** [July 13, 2006, 4:16pm UTC](https://www.ruby-forum.com/t/render-partial-questions/98254/4 "2006-07-13T16:16:24Z")

</div>

Stephen B. wrote on 13.07.2006 15:31:

> > But a render :partial doesn’t execute the TwoController index action  
> > which sets variables for its index view
> 
> Try this:
> 
> We have a orders controller and a people controller with a partial in  
> people:
> 
> render(:partial =\> ‘people/my\_partial’)

But as I wrote this renders only this partial view and does nothing with  
people controller.  
So let’s say in people/\_my\_partial.rhtml there is a \<%= @people.name %\>.  
In orders/index.rhtml is a  
\<%= render(:partial =\> ‘people/my\_partial’) %\>

This would not work because people(.name) is not available which would  
get set in the PeopleController action.

So how can you do this without setting @people in OrdersController  
action. That would be ugly.

Markus

---

<div class="post-metadata">

**Author:** ![subroutine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@subroutine](https://www.ruby-forum.com/u/subroutine)\
**Post date:** [July 13, 2006, 6:16pm UTC](https://www.ruby-forum.com/t/render-partial-questions/98254/5 "2006-07-13T18:16:32Z")

</div>

> We have a orders controller and a people controller with a partial in  
> people:
> 
> render(:partial =\> ‘people/my\_partial’)
> 
> If there is a slash, rails will use app/views/ as the base rather than  
> the current controller’s directory.
> 
> I wouldn’t recommend using components (also suggested) as they’re  
> notoriously in-efficient and there is word of them being phased out…

I’m doing the same thing, my question is:

If your above render is in the orders controller how do you suggest  
populating  
the data required by the people partial? Call directly into the people  
controller?

At least with components you can invoke a method AND get a view.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![subroutine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@subroutine](https://www.ruby-forum.com/u/subroutine)\
**Post date:** [July 13, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/render-partial-questions/98254/6 "2006-07-13T16:51:07Z")

</div>

Michael S. wrote on 13.07.2006 15:24:

> See render\_component

Thanks. But in the API you can read: “So to repeat: Components are a  
special-purpose approach that can often be replaced with better use of  
partials and filters.”

So is my stuff below replaceable and should it be replaced by partials?

---

<div class="post-metadata">

**Author:** ![subroutine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@subroutine](https://www.ruby-forum.com/u/subroutine)\
**Post date:** [July 14, 2006, 1:01am UTC](https://www.ruby-forum.com/t/render-partial-questions/98254/7 "2006-07-14T01:01:06Z")

</div>

If you have something that’s loaded in more than one controller, either  
create a application helper or use a before\_filter calling a method set  
in application controller.

Steve
