Some Guy
Some Guy

Reputation: 13568

I'm developing a Ruby gem, how can I try it out locally with my Rails app?

I am developing a gem meant to be used with Rails projects and want to try it out locally with another Rails app of mine.

I built the gem with bundle exec rake release which put a .gem file in the /pkg directory.

Then, in my Rails app, I added the following to my gemfile

gem 'mygem', '0.1.1', path: '/Users/me/projects/mygem/ruby/pkg'

I then ran bundle install which said it installed the gem. When I do this, it removes the gem from the path. IDK where it went.

When I start the Rails app, it's like the gem isn't included at all.

Interestingly, if I add a version that doesn't even exist, it still says bundle install works fine. (Example: gem 'mygem', '0.1.2345', path: '/Users/me/projects/mygem/ruby/pkg')

What am I supposed to do to try out my Gem locally with a Rails app?

This question is different from How can I specify a local gem in my Gemfile? because I explicitly tell bundle in my Gemfile to use the local gem, with the path given, and it still doesn't work. When I run bundle install, it says

Using mygem 0.1.1 from source at /Users/me/projects/mygem/pkg

So you'd think it works right, but it still doesn't.

Interestly, if I try it with a version number that doesn't exist, like mygem 1.2.3, it still runs bundle install successfully, which is really weird and seems like a bug:

Using mygem 1.2.3 (was 0.1.1) from source at /Users/me/projects/mygem/pkg

Upvotes: 0

Views: 305

Answers (1)

Collin Graves
Collin Graves

Reputation: 2257

I prefer to use the following when working on a local gem side-by-side with a Rails project:

gem 'foo',
  :git => '/path/to/local/git/repo',
  :branch => 'my-fancy-feature-branch'

Upvotes: 2

Related Questions