# ActionView: render a layout not in app/views?

**URL:** <https://www.ruby-forum.com/t/actionview-render-a-layout-not-in-app-views/150925>\
**Category:** Rails\
**Created:** [October 14, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/actionview-render-a-layout-not-in-app-views/150925 "2008-10-14T23:25:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjacobs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mjacobs](https://www.ruby-forum.com/u/mjacobs)\
**Post date:** [October 14, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/actionview-render-a-layout-not-in-app-views/150925/1 "2008-10-14T23:25:07Z")

</div>

Hey there,  
I have a problem.

class ApplicationController  
layout :determine\_layout

def determine\_layout  
“…/…/public/sites/#{@site.code}/application”  
end  
end

in rails2.0 this worked, but it was clearly a hack.

I tried to fix it in a few ways;

1. symlink public/sites -\> app/views/layouts/sites

- this breaks because the Dir.glob used to find view files doesnt work  
for subfolders of a symlink

1. set ApplicationController.view\_paths \<\< “public/sites”

- this doesnt quite seem to work.

1. manually fix rails and work out the best way to patch it for 2.2.1

- this seemed to work, but isn’t quite plugin-able as a fix

mostly I’m wondering,  
what is the right way to do this?

MatthewRudy

---

<div class="post-metadata">

**Author:** ![mjacobs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mjacobs](https://www.ruby-forum.com/u/mjacobs)\
**Post date:** [October 15, 2008, 1:37am UTC](https://www.ruby-forum.com/t/actionview-render-a-layout-not-in-app-views/150925/2 "2008-10-15T01:37:35Z")

</div>

Quite often I’m tasked with doing something very similar. Check out my  
solution:

class ExperiencesController \< ApplicationController  
self.view\_paths \<\< File.join(RAILS\_ROOT, “cms”, “experiences”)

def show  
render :layout =\> “1/layout”  
end  
end

requiring a folder structure like:  
RAILS\_ROOT/  
app/  
cms/  
experiences/  
1/  
layout.html.erb  
config/  
…

Does that help?

On Oct 14, 4:25 pm, Matthew R. Jacobs \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![mjacobs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mjacobs](https://www.ruby-forum.com/u/mjacobs)\
**Post date:** [October 15, 2008, 11:41am UTC](https://www.ruby-forum.com/t/actionview-render-a-layout-not-in-app-views/150925/3 "2008-10-15T11:41:50Z")

</div>

Andrew B. wrote:

> Quite often I’m tasked with doing something very similar. Check out my  
> solution:
> 
> class ExperiencesController \< ApplicationController  
> self.view\_paths \<\< File.join(RAILS\_ROOT, “cms”, “experiences”)
> 
> def show  
> render :layout =\> “1/layout”  
> end  
> end
> 
> requiring a folder structure like:  
> RAILS\_ROOT/  
> app/  
> cms/  
> experiences/  
> 1/  
> layout.html.erb  
> config/  
> …
> 
> Does that help?
> 
> On Oct 14, 4:25ï¿½pm, Matthew R. Jacobs \<rails-mailing-l…@andreas-

Hey thanks andrew,  
that’s the same thing I’m trying to achieve,  
although the code as such won’t quite work in Rails 2.1.1

it’ll give you errors about “found a view path that is not in the right  
format”

the correct way is  
append\_view\_path(…)

and you pointed out my error

I was doing;  
append\_view\_path(“public/sites”)

while actually what is required;  
append\_view\_path(File.join(Rails.root, “public”, “sites”))

works great, it seems.  
Thanks.

---

<div class="post-metadata">

**Author:** ![mjacobs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mjacobs](https://www.ruby-forum.com/u/mjacobs)\
**Post date:** [October 15, 2008, 10:19pm UTC](https://www.ruby-forum.com/t/actionview-render-a-layout-not-in-app-views/150925/4 "2008-10-15T22:19:40Z")

</div>

Matthew R. Jacobs wrote:  
tthew Rudy J. \<rails-mailing-l…@andreas-

> Hey thanks andrew,  
> that’s the same thing I’m trying to achieve,  
> although the code as such won’t quite work in Rails 2.1.1
> 
> it’ll give you errors about “found a view path that is not in the right  
> format”
> 
> the correct way is  
> append\_view\_path(…)
> 
> and you pointed out my error
> 
> I was doing;  
> append\_view\_path(“public/sites”)
> 
> while actually what is required;  
> append\_view\_path(File.join(Rails.root, “public”, “sites”))
> 
> works great, it seems.  
> Thanks.

Wrote a quick blog post about this;  
[http://rudygems.com/post/54730156/rendering-layouts-that-live-in-public](http://rudygems.com/post/54730156/rendering-layouts-that-live-in-public)
