Multi-tenancy (SaaS)


#1

I’m using Ruby on Rails as my API and I would like to know how I’d go about doing multi-tenancy for my app as a SaaS. On the rails side I see there is a gem called ‘acts_as_tenant’ which seems to work really well.

What’s puzzling me the most is the sub-domain so on the rails side it knows what ‘account’ is being used and returns the appropriate data to the front end. I haven’t found anything in the documentation that handles the sub-domain in the routes and allowing it to be passed to the Rails backend. Please ask me any questions if I’m not making myself clear so I can get some advice for how I can do this.


#2

The same Ember App is going to consume API from different endpoints, or each Ember app has its own API endpoint, and you’re rendering a different app depending on the user account/role?


#3

I will have one Ember App and one Rails App. What I’d like to do is the Ember App to detect the sub-domain and pass that to the Rails App to respond back with the accounts data.

Is that clear?


#4

That’s definitely doable. If you’re using ember-data try setting the host property on the adapter: http://emberjs.com/guides/models/customizing-adapters/#toc_host-customization . If you are not using ember-data you will need to set the host for each of your $.ajax requests.


#5

@xrl that looks interesting and I’ll look into this, thank you. Do you know how I can test this while in development mode, in Rails we use ‘Pow’ is there anything similar which can be used with emberjs?


#6

I use Pow with Ember. Just use Pow’s port proxying.

If, for example, you are using ember-cli on port 4200, then echo 4200 > ~/.pow/my-project and it will be available at http://my-project.dev as long as you are running the ember server. I tend to use this technique for rails projects as well :smile:


#7

Thanks @amiel. I’ll look into this.