Reddirt
Reddirt

Reputation: 5953

Rails - how to make your app work with multiple sub-domains

I am writing a RoR app. I would like to allow multiple clients of mine use it as a cloud based application. I don't want to have to duplicate the code for each customer.

I assume this means using a subdomain for each of my customers, and have a table for Customers. The Customers table would have a field for the domain.

In other words -- I want each customer to only see their records.

My questions are:

Any thoughts would help! Thanks!

Upvotes: 0

Views: 224

Answers (3)

cmrichards
cmrichards

Reputation: 1772

You also need to think about authorisation, ie does the current user have the permission to view/update these records? I personally recommend the cancan gem for this purpose https://github.com/ryanb/cancan, you define a single model/abilities.rb file in your app that contains all the permissions for your user. I've found it works really well.

Upvotes: 1

Raed
Raed

Reputation: 258

Has someone documented how to do this in Rails? Where is it?

The whole thing? Not that I am aware of.

For the subdomain? Yes, and it is called catch-all A record, catch-all subdomain, ... etc. Simply, add a wildcard (*) A record to the domain and then use request.subdomain in RoR to extract the subdomain requested.

@cheeseweasal answered the rest.

Upvotes: 0

Sam Peacey
Sam Peacey

Reputation: 6034

There's a railscast about handling subdomains in Rails 3 here: http://railscasts.com/episodes/221-subdomains-in-rails-3

Regarding point 2, you'd just need the customer_id on Project, you wouldn't need it on Task as well.

I'm not sure what you mean about starting each view with Customer., but I'm guessing not. Maybe going through the railscast will answer your question here.

Upvotes: 1

Related Questions