Chad Johnson
Chad Johnson

Reputation: 21895

Most common practice for sharing data and models across Rails applications

I want to share data across two separate Rails applications.

Each application has the concept of a product. The two applications share common fields (eg. id, name) but each application also has fields that the other application does not need (eg. some_application_specific_flag).

What is the most common architectural practice as far as 1) sharing Rails models and 2) database structure?

Models: Completely separate models? Common base models and subclasses for each application? Something else?

Database structure: A common table for shared data and then application-specific tables for application-specific data?

Upvotes: 2

Views: 300

Answers (1)

Evgeny Shadchnev
Evgeny Shadchnev

Reputation: 7388

Ruby gem is often a good solution, you can include common models into it. In our company we use a ruby gem to contain common logic for several online shops. For another set of projects, a ruby gem contains all style-related stuff to make several separate websites looks like one.

Whether to use separate models or subclasses is up to you and your application. It depends. I would try to use separate models unless there's a good reason not to.

If you're just sharing data, that can be either a ruby gem (if you have very little data) or a database. In a database, I would use either a common table or a common database, depending on the volume and complexity of the data. I'd probably go for a common database (as opposed to a table) in most cases.

Upvotes: 1

Related Questions