I am building a series of Rails applications for different use cases, but they all are using the same database schema. All the migrations and models are created in the Main app. What is a common approach in Rails to reuse models in other apps in order not to duplicate code?
-
2Rails engines?Marek Lipka– Marek Lipka2014-03-24 11:23:06 +00:00Commented Mar 24, 2014 at 11:23
-
And is any other approaches ? What do you think of the solution described in this article hiltmon.com/blog/2013/10/14/rails-tricks-sharing-the-model ?egor_hm– egor_hm2014-03-24 11:29:06 +00:00Commented Mar 24, 2014 at 11:29
Add a comment
|
1 Answer
What you're looking to do is called Multitenancy. Its explanation and numerous ways of implementation aren't suited to a short SO answer, since there are many different use cases.
There are many guides that show you how to do this, though, and I've listed a couple starting points below.
- Railscast - Multitenancy with PostgreSQL
- Railscast - Multitenancy with Scopes
- Slideshow - Multitenancy with Rails
- Book - Multitenancy with Rails
Alternatively, the Acts As Tenant gem will attempt to abstract this pain away from you (mostly).