How do I do multiple layouts for a single controller: I am aware I can do... render(:layout =>''mylayout'') for individual actions, however this becomes a multiple render problem. I tried this... layout "mylayout", :except => [:myaction, :myotheraction] layout "myotherlayout", :only => [:myaction, :myotheraction] However that doesn''t work, I just get blank layouts for :myaction and :myotheraction Suggestions? ~Jamie -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060718/efa32139/attachment.html
On 7/18/06, Jamie Quint <jsquintz@gmail.com> wrote:> How do I do multiple layouts for a single controller: > > I am aware I can do... render(:layout =>''mylayout'') for individual > actions, however this becomes a multiple render problem. > > I tried this... > > layout "mylayout", :except => [:myaction, :myotheraction] > layout "myotherlayout", :only => [:myaction, :myotheraction] > > However that doesn''t work, I just get blank layouts for :myaction and > :myotheraction > > Suggestions? > > ~Jamie > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >layout :choose_layout def choose_layout ["myaction", "myotheraction"].include?(action_name) ? "myotherlayout" : "mylayout" end
Thanks! I didn''t know that "action_name" was available Explanation to others who may be wondering... # rails will look for a layout named "choose_layout" and if it doesn''t find it look for an action named "choose_layout" layout :choose_layout # define a method that will select the proper layout and make it private private def choose_layout #see if login or signup is the requested action name where "action_name" is a variable set by rails. ["login","signup"].include?(action_name) # if this is true then render "account" otherwise render "standard" ? "account" : "standard" end On 7/18/06, Pat Maddox <pergesu@gmail.com> wrote:> > On 7/18/06, Jamie Quint <jsquintz@gmail.com> wrote: > > How do I do multiple layouts for a single controller: > > > > I am aware I can do... render(:layout =>''mylayout'') for individual > > actions, however this becomes a multiple render problem. > > > > I tried this... > > > > layout "mylayout", :except => [:myaction, :myotheraction] > > layout "myotherlayout", :only => [:myaction, :myotheraction] > > > > However that doesn''t work, I just get blank layouts for :myaction and > > :myotheraction > > > > Suggestions? > > > > ~Jamie > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > layout :choose_layout > > def choose_layout > ["myaction", "myotheraction"].include?(action_name) ? > "myotherlayout" : "mylayout" > end > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060718/1fbcbe8e/attachment-0001.html
On 7/18/06, Jamie Quint <jsquintz@gmail.com> wrote:> Thanks! I didn''t know that "action_name" was available > > Explanation to others who may be wondering... > > # rails will look for a layout named "choose_layout" and if it doesn''t find > it look for an action named "choose_layout" > layout :choose_layout > > # define a method that will select the proper layout and make it private > > private > def choose_layout > #see if login or signup is the requested action name where "action_name" > is a variable set by rails. > ["login","signup"].include?(action_name) > # if this is true then render "account" otherwise render "standard" > ? "account" : "standard" > endI''m wondering if this would be worth a bug report. As I understand you''re supposed to be able to use layout ''whatever'', :only => [''this'', ''that'']. Maybe it''s only in the newest versions though.
On 7/18/06, Chuck Vose <vosechu@create-on.com> wrote:> On 7/18/06, Jamie Quint <jsquintz@gmail.com> wrote: > > Thanks! I didn''t know that "action_name" was available > > > > Explanation to others who may be wondering... > > > > # rails will look for a layout named "choose_layout" and if it doesn''t find > > it look for an action named "choose_layout" > > layout :choose_layout > > > > # define a method that will select the proper layout and make it private > > > > private > > def choose_layout > > #see if login or signup is the requested action name where "action_name" > > is a variable set by rails. > > ["login","signup"].include?(action_name) > > # if this is true then render "account" otherwise render "standard" > > ? "account" : "standard" > > end > > I''m wondering if this would be worth a bug report. As I understand > you''re supposed to be able to use layout ''whatever'', :only => [''this'', > ''that'']. Maybe it''s only in the newest versions though. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >You can use layout :only and layout :except, but you can only use one of them in any given controller. It''s a really common question, and it''s worked that way for a long, long time so it''s not a bug. I couldn''t tell you the reasoning behind it though. Pat