Render :action of a different controller

Hi, it may be trivial, but i couldn't find any [clear] documentation on the parameters passed to the render method when using the :action. I just want to know if and how i can use this method for rendering an action's layout that belongs to a different controller. Something like "render :action => list, :controller => blog" for example...

Thanks a lot in advance :slight_smile:

-Nikos

Yes, I’m fairly sure you can do that, exactly like your example, actually.

–Tyler Prete

For some reason my previous mail didn't show up here.... grrrr i hate it when i have to rewrite something that's long enough to take me 15 minutes to write again :slight_smile: Anyway here it goes...

I tried what you said that worked for you so i could verify it and also add some hints on the documentation of ActionController::Base but didn't quite worked for me... Here's what i tried:

class GoalsController < ApplicationController   def short_goal   end   def long_goal   end end

class FoulsController < ApplicationController   def penalty     if true       render :action => 'short_goal', :controller => 'goals'     end   end end

and the views accordingly... The result when hitting fouls/penalty was "Template missing. Missing template ./script/../config/../app/views/ FOULS/short_goal.rhtml"

After reading the source for ActionController::Base#render which calls ActionController::Base#render_action when :action is passed i thought that this result makes sense (at least to me). The source if you're feeling lazy is:

      def render_action(action_name, status = nil, with_layout = true) #:nodoc:         template = default_template_name(action_name.to_s)         if with_layout && !template_exempt_from_layout?(template)           render_with_layout(:file => template, :status => status, :use_full_path => true, :layout => true)         else           render_without_layout(:file => template, :status => status, :use_full_path => true)         end       end

where "action_name" is the value of :action

So i tried the following:

class FoulsController < ApplicationController   def penalty     if true       render :action => '../goals/short_goal'     end   end end

and worked. The thing is that i don't think this is a 'nice' way of doing this - the smell of bugs is close :slight_smile:

Also how can i call the action before rendering the view to set up the variables. *** I know i should probably do a redirect instead all this fuzz but curiosity is driving me at the moment :slight_smile: ***

Waiting for your thoughts/comments/suggestions :slight_smile:

-Nikos

Also how can i call the action before rendering the view to set up the variables. *** I know i should probably do a redirect instead all this fuzz but curiosity is driving me at the moment :slight_smile: ***

I think you're looking for render_component (http:// api.rubyonrails.org/classes/ActionController/Components.html)

Khaled

Yeah, i think this makes sense :slight_smile:

Thanks a lot Khaled