0

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
Community
  • 1
  • 1
Some Guy
  • 12,768
  • 22
  • 58
  • 86
  • There is a really good number of answers on [this previous question](http://stackoverflow.com/questions/4487948/how-can-i-specify-a-local-gem-in-my-gemfile) – creativereason Jul 07 '15 at 23:58
  • @creativereason I actually did exactly follow one of the previous questions, and yet it doesn't work. That's why I added details that puzzle me, like how if I require a version that doesn't exist, bundle install still seems to run successfully. Why would it do that? There must be something I'm doing wrong... – Some Guy Jul 08 '15 at 00:03
  • I am not sure the version matters when you use path? Did you try the other answers? Specifically [Bloudermilk's option](http://stackoverflow.com/a/14167368/1208166)? – creativereason Jul 08 '15 at 00:09
  • The version apparently does matter when you use path, because when I didn't have a version listed, bundle install failed. I saw bloudermilk's answer but I am not using Github or even git yet for the gem, so I don't think it'd work. Regardless, my syntax seems like it should work, no? – Some Guy Jul 08 '15 at 00:25
  • 'path` isn’t for specifying where to find the built Gem file locally, it is for pointing to the unpacked source directory for the gem. In your case it would be something like `gem 'mygem', path: '/Users/me/projects/mygem'`. – matt Jul 08 '15 at 02:03

1 Answers1

2

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'
Collin Graves
  • 2,207
  • 15
  • 11