jason
May 2, 2007, 7:38pm
1
I have a controller where everything uses the same layout except for one
action called view. I tried this at the top of the controller:
layout “remote”, :only => [:view]
layout “standard”, :except => [:view]
This renders standard for :view, and the other actions don’t use a
layout at all!
How can I get what I want here?
Thanks!
jason
May 2, 2007, 7:51pm
2
in your action:
render [render stuff], :layout => ‘layout_name’
Jason
jason
May 2, 2007, 8:00pm
3
Jason R. wrote:
in your action:
render [render stuff], :layout => ‘layout_name’
Jason
I tried that, but my controller does checking on db stuff, and if it
fails, I do a redirect_to, then I get an error about render and
redirect_to in the same action.
jason
May 2, 2007, 8:07pm
4
In the controller:
layout :layout_a, :except => :fred
layout :layout_b, :only => fred
Michael
jason
May 2, 2007, 8:29pm
5
MichaelLatta wrote:
In the controller:
layout :layout_a, :except => :fred
layout :layout_b, :only => fred
Michael
I tried that too, and got the result I mentioned in my first post. I
tried it without giving an array, as well.
jason
May 3, 2007, 4:41am
6
Ugly, but use the method version of layout:
layout :standard_or_remote
def standard_or_remote(controller)
if controller.action_name == ‘view’
‘remote’
else
‘standard’
end
end
jason
May 3, 2007, 3:15pm
7
layout :standard_or_remote
def standard_or_remote(controller)
if controller.action_name == ‘view’
‘remote’
else
‘standard’
end
end
I think that would work great. I decided yesterday to move the view
action to a different controller that fit it better logically anyway.
Thanks everyone for your help!
jason
June 18, 2007, 8:39pm
8
Don’t forget:
def standard_or_remote(controller)
controller.action_name == ‘view’ ? ‘remote’ : ‘standard’
end
jason
May 3, 2007, 6:50am
9
Jason wrote:
You can always put the test in an if/else…
b