I just created a new gem (using bundler) and want to add Active Record support. So I added s.add_dependency "activerecord", "~> 3.0" to my gemspec. Then I use Bundler.setup and Bundler.require and thought that I have access to Active Record now, but I haven’t. I have to explicitly use require "active_record". Any idea why Bundler.require does not work for me in that case?
I just created a new gem (using bundler) and want to add Active Record
Share
Firstly, if you’re packaging a gem, do not use
Bundler.require.Bundler.requireis for apps not gems.In
.gemspec, specify the dependencies of your deployed gem.In your
Gemfile, include the linegemspecto automatically include the dependencies listed in your.gemspecin yourGemfile.You may also optionally create gem groups for dev and test.
In your code, explicitly
requireany libraries you need.I lost a couple of hours on this today so I hope this helps.
(Sources 1, 2)
Secondly, though the ActiveRecord gem is called “activerecord”, the lib is called “active_record”. This is what you would need in
Gemfile.Unless you include the
:requireoption, ActiveRecord won’t be loaded correctly and you won’t know about it until you try to use it.