I need to add to every retrieved record a condition “client=xxx”. How do
I alter default conditions globally when retrieving records in
ActiveRecord?
Some background:
I’ve built a website / web service to be used just by a company. Now
we’re trying to make the service available to other companies. The
accounts will share the same codebase (think Salesforce.com). The
options are:
- Multiple databases (one for each account)
- easy to implement at the beginning
- hell to maintain
- The same database for all the data + some ruby magic
- easier to maintain in the long term (?)
- how to do it?
I will have a subdomain or a url parameter that will tell the name of
the company using our software. When reading records I need to override
the default conditions to add a parameter “client=company_id”. I will
add a before_filter on save in every model to add
“self.client=company_id”.