How to convert rails app to gem?

I have a ruby ​​on rails application which should be gem-ified. Jeweler, helps to create basic rubigems. However, how do I package the rails app as a gem? I have a main application that requires my rails application as a gem. I can’t integrate them, since the main rails application should be used as a management application for managing small applications that work in it like gems / engines.

+5
source share
1 answer

Since Rails 3.0, any Rails application is an engine. To wrap an application in a gem, you must:

  • Create a new gem with a bundle or jeweler or something else.
  • Paste the application code into the lib / directory of your gem.
  • All classes in your application must be in the MyGem module, so add MyGem before the class names, for example: Article => MyGem :: Article. All your controllers, models, etc. Must have names with the GemName module.
  • Your lib / my_gem.rb file should contain the following code:

    module MyGem
      class Engine < Rails::Engine; end
    end
    

UPD

Or better if you use mounted motors:

$ rails plugin new MyGem

He creates a mountable engine with a dummy test application and gemspec.

+4
source

All Articles