On 11/17/06, Anand S. [email protected] wrote:
My webapp can be accessed in two different contexts. I want to be able to
render the same view with two different layouts based on the context.
Is there a way to dynamically set the layout of the views based on the
context? ie, if I have a param value which indicates the context type, can
I change the layout dynamically?
Any help would be appreciated.
The classic (builtin) approach is to call
render :layout => ‘other_layout’
in your action.
I would also recommend considering my nested_layouts plugin (
http://nested-layouts.rubyforge.org/) to do it in your view, e.g.
class FooController < ApplicationController
@layout = ‘first’
@layout = ‘second’
<% inside_layout polymorphic_layout do %>
<%= yield %>
<% end %>
That’s it. The advantage is that you don’t need to specify proper layout
Hope that helps.