Finding layouts

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.

On 10/30/07, Gary D. [email protected] 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”)