1

I'm developing a ruby application that uses the models and data from another Ruby on Rails web application as its main data source.

The Rails models were included in this application by including the environment.rb file in the main file like this:

# Require Rails
 require_relative "../../RailsApp/config/environment.rb"

This works but there are uninitialized dependencies when loading models that use gems that are defined in the Rails Gemfile. (For example, acts_as_taggable_on, rack-pjax, devise, etc)

This ruby application dependencies are also managed through Bundler, so at the moment the only way to get the application working is to copy and paste the contents from the Rails' Gemfile into the ruby app's Gemfile.

Obviously this approach is not optimal as the gem requirements are duplicated.

Is there a better way to include Rails and the dependencies that its models require in another application? Is there a way to include a Gemfile into another?

2 Answers 2

6

Here are some options, in order of simplicity

  1. Just keep everything in one app, a lot of stuff is easier this way
  2. Use plugins to share common code
  3. Use web services to share data
1
  • Finally I went with number 3, we created a directory under /vendor/app_name and managed to get rid of the duplicate gemfiles and created rake tasks under rails that require the environment, so I don't need to include the rails models anymore. Thanks
    – bbonamin
    Sep 7, 2012 at 19:31
3

You could extract the models and code out from RailsAppA into a Gem. RailsAppA then includes that Gem and uses it.

The gem can remain in a private repository and does not need published.

Both apps would then do something like:

gem "yourapp-modelage", git: "http://github.com/you/yourapp-modelage.git"

Then, App2 would also use that Gem... How much goes into the Gem will depends on how much you need to re-use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.