Hi, I am trying to select a layout for a page based on what action is called. ex. if controller.action_name == ''about'' layout "internal" else layout "home_static" end But I am receiving this error: undefined local variable or method `controller'' for HomeController:Class Is there any way that I can do this? Is this even possible? Thanks, Jonathon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hmm, not sure if this will work, but since the controller is the object and the "actions" are just methods then: if self.respond_to?(about) layout "internal" else layout "home_static" end On Jul 13, 4:27 pm, "Jonathon Paul Martin" <jonathon.p.mar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I am trying to select a layout for a page based on what action is called. > ex. > > if controller.action_name == ''about'' > layout "internal" > else > layout "home_static" > end > > But I am receiving this error: > > undefined local variable or method `controller'' for HomeController:Class > > Is there any way that I can do this? Is this even possible? > > Thanks, > > Jonathon--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 7/13/07, Jonathon Paul Martin <jonathon.p.martin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I am trying to select a layout for a page based on what action is called. > ex. > > if controller.action_name == ''about'' > layout "internal" > else > layout "home_static" > endI''m not sure whether layout can be called conditionally this way, but I *am* sure that "controller" is an instance variable, not a local variable. Try something like: if @controller.action_name == ''about'' layout "internal" else layout "home_static" end Craig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
gene.tani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jul-14 02:49 UTC
Re: Determining Action in the Controller
On Jul 13, 1:27 pm, "Jonathon Paul Martin" <jonathon.p.mar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I am trying to select a layout for a page based on what action is called. > ex. > > if controller.action_name == ''about'' > layout "internal" > else > layout "home_static" > end > > But I am receiving this error: > > undefined local variable or method `controller'' for HomeController:Class > > Is there any way that I can do this? Is this even possible? > > Thanks, > > JonathonHmm, interesting question, you could look at how Radiant or Typo or other apps do themes, e.g. http://mattmccray.com/svn/rails/plugins/theme_support/ http://ragnarson.blogspot.com/2006/04/dynamic-templateroot-revisited.html http://ragnarson.blogspot.com/2006/03/dynamic-templateroot.html http://ostracons.com/entry/259/full-plates --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Found out the answer. layout :choose_layout private def choose_layout if [ ''signup'', ''login'' ].include? action_name ''login'' else ''admin'' end end This works perfectly. From here: http://paulsturgess.co.uk/articles/show/41-how-to-specify-multiple-layouts-within-the-same-controller-in-ruby-on-rails --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---