Bundler.require not working for ActiveRecord in my jewels

I just created a new gem (using bundler) and want to add Active Record support. Therefore, 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 donโ€™t have it. I have to use it explicitly require "active_record". Any idea why Bundler.require is not working for me in this case?

+3
source share
3 answers

First, if you are packing a gem, do not useBundler.require . Bundler.requirefor non gem applications.

  • In .gemspecindicate the dependencies of your deployed gem.

  • In your Gemfileinclude line gemspecto automatically include the dependencies listed .gemspecin your Gemfile.

    You can also create gem groups for dev and test.

  • There are clearly requireany libraries you need in your code .

Today I lost a couple of hours, so I hope this helps.

(Sources 1 , 2

Secondly, although the ActiveRecord stone is called "activerecord", the lib is called "active_record". This is what you need at Gemfile.

gem 'activerecord', :require => "active_record"

If you have not enabled the option :require, ActiveRecord will not load correctly, and you will not know about it until you try to use it.

+11

Bundler, Gemfile Activerecord

gem 'activerecord', "~> 3.0.0"

bundler, gemspec gemspec Gemfile

gemspec

. http://gembundler.com/rubygems.html

+1

, , gem, :

lib ->
  active_record ->
    base.rb <- containing some monkey patches to base

, :

Gem Load Error is: uninitialized constant ActiveRecord::Base
Did you mean?  ActiveRecord::Base

lib/active_record/base.rb lib/active_record_base.rb .

0

Source: https://habr.com/ru/post/1771345/


All Articles