# Dinamic layout

**URL:** <https://www.ruby-forum.com/t/dinamic-layout/186611>\
**Category:** Rails\
**Created:** [April 9, 2010, 6:37pm UTC](https://www.ruby-forum.com/t/dinamic-layout/186611 "2010-04-09T18:37:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CiriusMex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/90ced4/32.png) [@CiriusMex](https://www.ruby-forum.com/u/CiriusMex)\
**Post date:** [April 9, 2010, 6:37pm UTC](https://www.ruby-forum.com/t/dinamic-layout/186611/1 "2010-04-09T18:37:11Z")

</div>

Hello, I am developing a RubyOnRails application and need to apply a  
layout dinamically to my controllers. The thing is I have 2 diferent  
layouts and, in function of a parameters retreived from the database  
when the page is loaded, I need my controllers to use on or the other  
of the two layouts.  
So I am looking for a way to do something like that:

class MyController \< ApplicationController  
layout “#{session[:layout]}”  
…  
end

Anyone know how I can do solve this?

Olivier.

---

<div class="post-metadata">

**Author:** ![CiriusMex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/90ced4/32.png) [@CiriusMex](https://www.ruby-forum.com/u/CiriusMex)\
**Post date:** [April 9, 2010, 6:55pm UTC](https://www.ruby-forum.com/t/dinamic-layout/186611/2 "2010-04-09T18:55:55Z")

</div>

On Apr 9, 5:35 pm, CiriusMex [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello, I am developing a RubyOnRails application and need to apply a  
> layout dinamically to my controllers. The thing is I have 2 diferent  
> layouts and, in function of a parameters retreived from the database  
> when the page is loaded, I need my controllers to use on or the other  
> of the two layouts.

Take a look at the docs for layout - you can supply a method that  
decides which layout to use.

Fred

---

<div class="post-metadata">

**Author:** ![CiriusMex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/90ced4/32.png) [@CiriusMex](https://www.ruby-forum.com/u/CiriusMex)\
**Post date:** [April 9, 2010, 7:36pm UTC](https://www.ruby-forum.com/t/dinamic-layout/186611/3 "2010-04-09T19:36:19Z")

</div>

Hello Fred,

Yeah I guess there is a way to do it but I didn’t find anything with  
google…You have any link I could check?

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![CiriusMex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/90ced4/32.png) [@CiriusMex](https://www.ruby-forum.com/u/CiriusMex)\
**Post date:** [April 9, 2010, 7:40pm UTC](https://www.ruby-forum.com/t/dinamic-layout/186611/4 "2010-04-09T19:40:25Z")

</div>

Sorry, I finaly did find something 🙂  
[http://apidock.com/rails/ActionController/Layout/ClassMethods/layout](http://apidock.com/rails/ActionController/Layout/ClassMethods/layout)
