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 -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Markus Kolb Sent: Thursday, July 13, 2006 9:06 AM To: rails@lists.rubyonrails.org Subject: [Rails] 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 _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
> 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 Bartholomew 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
Michael Scappa wrote on 13.07.2006 15:24:> See render_componentThanks. 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?>> 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.
> 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.
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 Brittain wrote:>> 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. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >