简体   繁体   中英

How to convert a rails app to a gem?

I have a ruby on rails app that needs to be gem-ified. Jeweler, helps create basic rubygems. However, how do I package a rails app as a gem? I have a main app that requires my rails app as a gem. I cannot integrate them as the main rails app is to be used as a management app to control smaller apps, running in it as gems/engines.

Since Rails 3.0 any Rails app is an Engine. For wrap your application to a gem you should:

  1. Create new gem with bundler or jeweler or something else.
  2. Insert your application code to lib/ directory of your gem.
  3. All classes of your app should be in MyGem module, so add MyGem before your class names, like: Article => MyGem::Article. All your controllers, models, etc. should be namespaced with module GemName.
  4. Your file lib/my_gem.rb should contain next code:

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

UPD

Or be better if you will use mountable engines:

$ rails plugin new MyGem

It generates mountable engine with dummy app for tests and gemspec.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM