Ask A Question


You’re not receiving notifications from this thread.

Best way to use common code for multiple applications ?

Pardha asked in Rails

Hi all,

   I would like to know the best way to use common code for multiple applications ?  Basically I am working on two applications those two are build on top of third party APIs . I want to extract the common logic for maintenance. Please let me know your thoughts .



Depending on what you're doing it may be worth extract the code into a Gem or an Engine.

Git Submodules is also a viable option. I've started using them to share common CSS and JS code between different rails apps.


Hi Leonid - Most of the sharable code is in POROs


In that case Gem or Engine is probably your best option. Check out this tutorial for some ideas on how engines could be used :)


As other say, create a gem.

Note: A Rails engine is just a gem with a type of setup that allows it to integrate with a Rails app. If the code is just plan ol' Ruby, life is even simpler. Follow one of the tutorials listed above, the RubyGems first gem tutorial, or the Rails plugin tutorial. Rails plugins are helpful if you're not using an Engine, but still want to test your code in the context of a Rail app.


Thanks - I am going to build Gem. :)

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,969+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.