Skip to main content

Best way to use common code for multiple applications ?

Rails • Asked by Pardha

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 .

Thanks,
Pardha



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 :) https://pchm.co/posts/tutorial-how-to-build-a-cms-in-ruby-on-rails


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. :)


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.