Using a different layout for just one action in controller

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!

in your action:

render [render stuff], :layout => ‘layout_name’

Jason

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.

In the controller:

layout :layout_a, :except => :fred
layout :layout_b, :only => fred

Michael

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.

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

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!

Don’t forget:

def standard_or_remote(controller)
controller.action_name == ‘view’ ? ‘remote’ : ‘standard’
end

Jason wrote:

You can always put the test in an if/else…

b

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs