简体   繁体   中英

How do I properly gem unpack a gem in a rails application?

I tried

rake gems:unpack
rake gems:unpack:dependencies 

Then i ran

rake gems:refresh_specs 

which gave me this error

undefined method `installed_source_index' for #<Gem::SourceIndex:0x100549718>

then i ran this

rake gems:install

Then i ran script/console and tried to use the gem and error

ITunesSearchAPI.lookup(:id => 3996865, :entity => :song)
NameError: uninitialized constant ITunesSearchAPI

this is

RAILS_GEM_VERSION = '2.3.8'

In case anyone else comes across the error above: "undefined method `installed_source_index' for #"

When running: rake gems:refresh_specs

The error is caused when rails 2.3.x is running as a gem as apposed to running from within your applications vendor/rails directory. It was reported and fixed https://rails.lighthouseapp.com/projects/8994/tickets/2978-rake-gemsrefresh_specs-not-working-as-expected

If you can't get the fix or if you'd rather work around it you can freeze your version of rails into your application first: rake rails:freeze:gems

Then try rake gems:refresh_specs again and it should work

On a side note, instead of unpacking gems, I've used bundler with 2.3 apps. Works like a charm and you can use it to cache your .gem files inside your app's vendor/cache folder.

Not an option for everyone, but if you can use bundler, it makes your life much easier.

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