KendallB KendallB - 1 year ago 71
Ruby Question

Working on gem within a Rails app

What's the easiest way to work on a plain-ole Ruby gem, and then quickly turn around and run it in a Rails app?

I like to keep application logic out of Rails. Encourages code reuse across projects, and keeps my Rails app clean. It produces, however, an ugly workflow:

  1. Test my gem.
    rake test

  2. Build my gem.
    gem build ...

  3. Upload gem to private repository (currently using Gemfury).
    fury push ...

  4. Update my gem from within Rails (bundle update ...)

  5. Run my Rails code.

Yuck. I'd like to simply save my file in the library, and then watch it work in the Rails project.

Clojure's Leiningen has a concept called "checkouts", allowing you to work on several libraries within one.

Techniques, anyone?

Answer Source

Use Bundler's path directive.

gem 'my_gem', :path => "~/my_gem"

You'll still have to restart the Rails server every time your code changes to reload it, but you won't have to go through the whole build-and-publish step for each revision. Be sure to update your gem reference to something production-worthy before pushing your code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download