Kevin
Kevin

Reputation: 187

How to separate database information per user in Rails

I am looking for a solution to the problem that I will have many different users creating/signing into my web application that uses Rails, but the current application returns the same data from the database regardless of which user created/modified the data.

Is there a way that I can separate the information/data created and modified on a per user basis?

I found the following stackoverflow question that seems to be related to my issue, but was unsure if it would solve my problem and/or how to implement it. Rails - Separate Database per Subdomain

Thanks.

Upvotes: 1

Views: 685

Answers (2)

Jade
Jade

Reputation: 1

I recommend the gem named "Acts as tenant", simple and easy to implement. https://github.com/ErwinM/acts_as_tenant

Upvotes: 0

Akshay Pardhanani
Akshay Pardhanani

Reputation: 122

It looks like you are looking for a way to implement multi tenancy in your application. If that is in fact what you are looking for then you could take a look at the following two videos that use default_scope:

  1. General idea behind multitenancy and default_scopes
  2. Multi tenancy with PostgreSQL

Alternatively you could check out the apartment gem

Upvotes: 1

Related Questions