All threads / Best way to use common code for multiple applications ?

Ask A Question

Notifications

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 .

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

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.