Reputation: 5953
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:
Has someone documented how to do this in Rails? Where is it?
Would every table have to have a customer_id in it? Or if you have a Project table with the Customer_id, and then have tasks for the Project, you wouldn't need the customer_id in the Task record - right?
Any thoughts would help! Thanks!
Upvotes: 0
Views: 224
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
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
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