# More views for more domains

**URL:** <https://www.ruby-forum.com/t/more-views-for-more-domains/81687>\
**Category:** Rails\
**Created:** [January 11, 2007, 11:28am UTC](https://www.ruby-forum.com/t/more-views-for-more-domains/81687 "2007-01-11T11:28:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![michal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@michal](https://www.ruby-forum.com/u/michal)\
**Post date:** [January 11, 2007, 11:28am UTC](https://www.ruby-forum.com/t/more-views-for-more-domains/81687/1 "2007-01-11T11:28:05Z")

</div>

Hello

I have more than one domain and i want to create different views for  
each domain.

example i have:

- domain\_A,
- domain\_b

My question is how to create different views for each domain (each  
domain has its  
own view)?

Thanks

---

<div class="post-metadata">

**Author:** ![michal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@michal](https://www.ruby-forum.com/u/michal)\
**Post date:** [January 11, 2007, 4:49pm UTC](https://www.ruby-forum.com/t/more-views-for-more-domains/81687/2 "2007-01-11T16:49:39Z")

</div>

michal wrote:

> Hello
> 
> I have more than one domain and i want to create different views for  
> each domain.

Just to clarify, are you saying the two domains will go to the same  
app, with the same database, and do the same thing…but just look  
different?

Or are you essentially talking about two different apps on the two  
domains, but running on one server?

best,  
jp

---

<div class="post-metadata">

**Author:** ![michal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@michal](https://www.ruby-forum.com/u/michal)\
**Post date:** [January 17, 2007, 10:37pm UTC](https://www.ruby-forum.com/t/more-views-for-more-domains/81687/3 "2007-01-17T22:37:44Z")

</div>

I’m saying about one app with one database and more than only one  
domain.

Jeff P. wrote:

> michal wrote:
> 
> > Hello
> > 
> > I have more than one domain and i want to create different views for  
> > each domain.
> 
> Just to clarify, are you saying the two domains will go to the same  
> app, with the same database, and do the same thing…but just look  
> different?
> 
> Or are you essentially talking about two different apps on the two  
> domains, but running on one server?
> 
> best,  
> jp

---

<div class="post-metadata">

**Author:** ![michal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@michal](https://www.ruby-forum.com/u/michal)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/more-views-for-more-domains/81687/4 "2007-01-19T16:31:53Z")

</div>

You’ll need to work with request.domain [and possibly the array of  
request.subdomains] but I can’t tell if you’re talking about forcing  
wholly  
different layouts for each domain or merely having some controller  
methods  
use different views based on the domain. I can’t imagine a case for the  
second but that’s what your question sounds like. Clarification??

RSL

---

<div class="post-metadata">

**Author:** ![michal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@michal](https://www.ruby-forum.com/u/michal)\
**Post date:** [January 18, 2007, 3:17pm UTC](https://www.ruby-forum.com/t/more-views-for-more-domains/81687/5 "2007-01-18T15:17:43Z")

</div>

I’m going out on a limb here but I’d use

layout “x” if request.domain == “[domain-one.com](http://domain-one.com)”  
layout “y” if request.domain == “[domain-two.com](http://domain-two.com)”

for the layouts. (You may choose to use an if/else/end style.) For the  
views  
on each method you’ll have to call

def some\_method

# Code missing…

render :template =\> “blah/blah/blah” if request.domain ==  
“[domain-one.com](http://domain-one.com)”  
render :template =\> “bleh/bleh/bleh” if request.domain ==  
“[domain-two.com](http://domain-two.com)”  
end

or something. I would personally try to find a way to abstract that out  
as a  
filter on the actions. Something like

after\_filter :map\_to\_view\_by\_domain

private

def map\_to\_view\_by\_domain  
case request.domain  
when “[domain-one.com](http://domain-one.com)”  
render :template =\> “blah/blah/#{action\_name}”  
when “[domain-two.com](http://domain-two.com)”  
render :template =\> “bleh/bleh/#{action\_name}”  
end  
end

I’m not saying that’s valid code or anything but a rough idea. I think  
it  
should work but you’ll have to tool around with it. I’m currently logged  
into Windows [dual boot] and don’t have access to Ruby/Rails. I hope  
that  
works. Or at least puts you on the right track.

RS:
