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

Reply
Reply

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.

Reply

Hi Leonid - Most of the sharable code is in POROs

Reply

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

Reply

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.

Reply

Thanks - I am going to build Gem. :)

Reply
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.