# Finding layouts

**URL:** <https://www.ruby-forum.com/t/finding-layouts/118729>\
**Category:** Rails\
**Created:** [October 30, 2007, 1:44pm UTC](https://www.ruby-forum.com/t/finding-layouts/118729 "2007-10-30T13:44:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@jdgary](https://www.ruby-forum.com/u/jdgary)\
**Post date:** [October 30, 2007, 1:44pm UTC](https://www.ruby-forum.com/t/finding-layouts/118729/1 "2007-10-30T13:44:39Z")

</div>

I’m trying to find out whether a particular layout file exists at  
runtime. I need to potentially change the layout depending on which  
“site” a customer is visiting. I can do this by calling a method in the  
controller to determine the layout similar to:

def customer\_layout  
if @site\_id.nil?  
return “customer\_standard”  
else  
return “customer\_site\_” + @site\_id.to\_s  
end  
end

I need to determine if a particular site does indeed have a custom  
layout, if not then fall back to the standard one. So I need to see if  
“customer\_site\_123.rhtml” actually exists in the layout directory. The  
problem is I don’t want to hard code absolute paths that are certain to  
change on deployment.

Is there a way to determine what the current layout directory is so I  
can use that to try and find the file?

Eventually this will apply to css and image folders so any pointer there  
will help too.

Thanks,  
Gary.

---

<div class="post-metadata">

**Author:** ![jdgary](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@jdgary](https://www.ruby-forum.com/u/jdgary)\
**Post date:** [October 30, 2007, 3:47pm UTC](https://www.ruby-forum.com/t/finding-layouts/118729/2 "2007-10-30T15:47:01Z")

</div>

On 10/30/07, Gary D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m trying to find out whether a particular layout file exists at  
> runtime.  
> Is there a way to determine what the current layout directory is so I  
> can use that to try and find the file?
> 
> Eventually this will apply to css and image folders so any pointer there  
> will help too.

RAILS\_ROOT is the “top” of your application, so you can do a check like:

File.exists?(“#{RAILS\_ROOT}/app/views/layouts/somefile.rhtml”)
