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 :) -Nikos --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yes, I''m fairly sure you can do that, exactly like your example, actually. --Tyler Prete On 5/9/07, Nikos D. <demisone-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > 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 :) > > -Nikos > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yup - I''ve got that all over some of my own code on a site running right now. :) On 5/9/07, Tyler Prete <psyonic-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Yes, I''m fairly sure you can do that, exactly like your example, actually. > > --Tyler Prete > > On 5/9/07, Nikos D. < demisone-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > 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 :) > > > > -Nikos > > > > > > > > > > > > > >-- Terry (TAD) Donaghe http://tadspot.tumblr.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 :) 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 :) 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 :) *** Waiting for your thoughts/comments/suggestions :) -Nikos On May 10, 6:16 am, "Terry Donaghe" <terry.dona...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yup - I''ve got that all over some of my own code on a site running right > now. :) > > On 5/9/07, Tyler Prete <psyo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Yes, I''m fairly sure you can do that, exactly like your example, actually. > > > --Tyler Prete > > > On 5/9/07, Nikos D. < demis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > 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 :) > > > > -Nikos > > -- > Terry (TAD) Donaghehttp://tadspot.tumblr.com--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Nikos, I looked at this a bit - I was thinking of redirect:. def penalty redirect_to :controller => ''goals'', :action => ''short_goal'' end I guess that makes more sense because what your code is doing is taking the user to a totally different page than the penalty.rhtml page that you ought to go to when fouls.penalty is called. On 5/10/07, Nikos D. <demisone-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > 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 :) 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 :) > > 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 :) *** > > Waiting for your thoughts/comments/suggestions :) > > -Nikos > > On May 10, 6:16 am, "Terry Donaghe" <terry.dona...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Yup - I''ve got that all over some of my own code on a site running right > > now. :) > > > > On 5/9/07, Tyler Prete <psyo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > > Yes, I''m fairly sure you can do that, exactly like your example, > actually. > > > > > --Tyler Prete > > > > > On 5/9/07, Nikos D. < demis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > 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 :) > > > > > > -Nikos > > > > -- > > Terry (TAD) Donaghehttp://tadspot.tumblr.com > > > > >-- Terry (TAD) Donaghe http://tadspot.tumblr.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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 :) ***I think you''re looking for render_component (http:// api.rubyonrails.org/classes/ActionController/Components.html) Khaled --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yeah, i think this makes sense :) Thanks a lot Khaled On May 11, 2:50 am, Khaled Hassounah <khassou...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 :) *** > > I think you''re looking for render_component (http:// > api.rubyonrails.org/classes/ActionController/Components.html) > > Khaled--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---