QUESTION
How do I partition my app so that I can isolate personal and business
controllers under under a single or dual subdomain configuration?
OPTION 1
Create two subdomains for each account, personal.domain.com and
business.domain.com. If I take this approach, I see trouble down the
road when other parts of the app need to link back to the user's
account. At some point a decision will have to be made, is it
personal.domain.com or business.domain.com? If possible, I was thinking
that routes could be selected, in routes.rb, based on the session data,
(e.g. check for personal or business account)?
OPTION 2
Create a single account domain, my.domain.com, and then select the
correct controller/action for the user's account in the
ApplicationController. For example, in routes.rb (request routing plugin
installed):
map.with_options(:condition => {:subdomain => 'my'}) do |x|
x.connect '*path',
:controller => 'application',
:action => 'route_to_account'
end
Then the ApplicationController::route_to_account will handle the
controller/action routing to the personal or business controller/action
contingent upon session data. If I take this approach, it seems I loose
all the cool routing stuff, like named routes, and url variables in
@params?
What should I do? Any advice is greatly appreciated.
-pachl
--
Posted via http://www.ruby-forum.com/.
Starr
So my next question, where exactly would I map my controller, in
routes.rb or ApplicationController (as I mention in Option#2)?
When the request comes into the routing code, my only way of
determining if a user is a business or personal account is via
sessions[:business_id] (it will be nil for personal and set for
business). So how could I get at this session variable? Is there
another way of doing this?
> I don't see why you would loose any routing abilities.
If I take the option#2 approach, I wouldn't be able to setup named
routes like the following:
map.with_options(:condition => {:subdomain => 'my'}) do |x|
if session[:business_id]
# business account mappings ...
biz.connect ':action/:id', :controller => 'account/business'
else
# personal account mappings ...
per.connect ':action/:id', :controller => 'account/personal'
end
end
I want to take approach #2, but not sure how to do this using a single
subdomain that maps to two backend controllers. My only differentiator
between the two accounts is the session variable "business_id".
Is there a way to get at session data in config/routes.rb? If so, I
think I can acheive option#2!
I'm very new at Rails so a good explaination will be greatly
appreciated. This is my first time using Rails; I am rewriting an PHP
app.
-pachl