Question

I am developping a multi-server web application and I am wondering what are in ruby/rails the best practices concerning modularity.

Basically I am looking for the best way to share my ActiveRecord models from the rails application up to my background worker application (2 different heroku instances).

1) Share the same code for both the rails app and the background worker. We now have a big application that does everything. (Pro: it solve code sharing problem, Con: It make a bloated application)
2) bundle the ActiveRecord models in a gem and require it in both applications (Pro: modularity at it's best, Con: not easy in starting dev)
3) Copy active record models in both code bases (Con: code repeating, can induce errors when updating the database)

Now, I come from a .Net background. Normally I would put my models in a dll and that would solve the issue for sharing code, but I'm not exactly sure on what's the "ruby way" here.

Is there somewhere I should look for architecture best practices on the ruby way ?

Was it helpful?

Solution

Option 1. It may feel bloated, but Rails works best when kept DRY. And you may be surprised to see that it hasn't really become as bloated as you may have thought.

Separating out to a gem is doable, but should be restricted to framework or utility code. Business logic should be kept within the application if you want to keep Rails (and yourself) happy.

OTHER TIPS

You can put your shared models into a Rails Engine and package it up as a gem. A Rails Engine is like a miniature subset of a Rails app that can be reused in other Rails apps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top