Forum: Ruby on Rails More views for more domains.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
michal (Guest)
on 2007-01-11 11:28
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
46cf9d3ad0463b5da02964e4ce479dfa?d=identicon&s=25 Jeff P. (jeffpritchard)
on 2007-01-11 16:49
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
Michal (Guest)
on 2007-01-17 22:37
I'm saying about one app with one database and more than only one
domain.

Jeff Pritchard 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
Russell Norris (Guest)
on 2007-01-18 15:17
(Received via mailing list)
I'm going out on a limb here but I'd use

layout "x" if request.domain == "domain-one.com"
layout "y" if request.domain == "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"
  render :template => "bleh/bleh/bleh" if request.domain ==
"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"
   render :template => "blah/blah/#{action_name}"
  when "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:
Russell Norris (Guest)
on 2007-01-19 16:31
(Received via mailing list)
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
This topic is locked and can not be replied to.