Rails: Dividing up a single database between multiple subdomains -
i'm relatively new rails, , here situation:
i'm building inventory management app rails 3 separate branches of company manage own product inventory.
each of these 3 branches keeping track of same products, use same data models, managed separately. plan build single app using single database, 1 keeps track of inventory in 3 branches.
my plan have this:
branch1.inventoryapp.com
branch2.inventoryapp.com
branch3.inventoryapp.com
each subdomain lead same interface same functions , same views. difference actual content of inventory, list of products physically @ branch @ time.
will able rails subdomain routing?
should have separate controllers each branch?
should use controller namespaces? nested resources?
thanks in advance!
in application_controller, simply:
class applicationcontroller < actioncontroller::base before_filter :current_account helper_method :current_account def current_account @account ||= account.find_by_domain(request.subdomain) end end
then, everywhere else:
class widgetscontroller < applicationcontroller def index @widgets = current_account.widgets.paginate(:page=>params[:page]) end def show @widget = current_account.widgets.find(params[:id]) end def create @widget = current_account.widgets.build(params[:widget]) if @widget.save ... end end end
by scoping @account
, keeping data separate across subdomains.
you can use current_account
helper in views.
Comments
Post a Comment