# Dynamic layouts from DB

**URL:** <https://www.ruby-forum.com/t/dynamic-layouts-from-db/113497>\
**Category:** Rails\
**Created:** [August 31, 2007, 7:20pm UTC](https://www.ruby-forum.com/t/dynamic-layouts-from-db/113497 "2007-08-31T19:20:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [August 31, 2007, 7:20pm UTC](https://www.ruby-forum.com/t/dynamic-layouts-from-db/113497/1 "2007-08-31T19:20:24Z")

</div>

Hello,

I’m trying to get layouts from the database and use it as layout, but  
its not working as excepted, it always try to find something from the  
layout director

views/layouts/ \_\_\_ .rhtml

Even the below code render it as HTML and not ruby code

@layout = Layout.find(:first)  
@test = “test”  
render :text = @layout.html

Result:

joiasd jioasd ijoaidsoj ajiod \<%= @test %\>

I hope someone can point me in some direction, and thanks for your help  
🙂

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [September 1, 2007, 3:37pm UTC](https://www.ruby-forum.com/t/dynamic-layouts-from-db/113497/2 "2007-09-01T15:37:55Z")

</div>

nothing ☹ ?

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [September 3, 2007, 10:38am UTC](https://www.ruby-forum.com/t/dynamic-layouts-from-db/113497/3 "2007-09-03T10:38:23Z")

</div>

The only solution I could think of is…

def index  
@test = “adw”  
render\_layout(1)  
end

private  
def render\_layout(id)  
render :inline =\> Page.find\_by\_id(id).layout.html  
end
