I have a couple of Rails project which have some codebase in common. The common code consists of some ActiveRecord Models and an api on top of that. Currently I am duplicating the common code in all projects which is a very bad practice. Now I want to move the common code to a Ruby Gem. I am new to Ruby on Rails. I have looked at several Gem tutorials but could not find anything useful that will help me create a gem with reusable ActiveRecord models.
Essentially I want is that -
Please let me know what are the best practices for such case.
I remember having the same issue with my ecommerce project and later I moved it to separate repository. By simply moving the whole repetitive code to a rails engine.
There are couple of guides available which you can follow:
http://edgeguides.rubyonrails.org/engines.html
http://coding.smashingmagazine.com/2011/06/23/a-guide-to-starting-your-own-rails-engine-gem/
http://railscasts.com/episodes/277-mountable-engines
You can create a generator to install your migration files of your models. So, whenever you mount your rails engine to any rails application and run generators. You'll be up and running with just few commands like: rake db:migrate
etc..
Well, what I shared is my experience. I do not know if there is any other better way of doing it.
P.S.: Here is the link to repository of engine I created - https://github.com/suryart/spree_active_sale, maybe code there can help you as a reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With