Render partial questions

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

See render_component

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

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

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.

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?

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs