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
On 7/18/06, Jamie Q. [email protected] wrote:
However that doesn’t work, I just get blank layouts for :myaction and
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, Jamie Q. [email protected] wrote:
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.
On 7/18/06, Chuck V. [email protected] wrote:
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
[email protected]
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