0

In my Gemfile I have:

source 'https://rubygems.org'

gem 'pry'
gem 'pg'
gem 'activerecord'

In my app.rb file I have:

require 'active_record'
require 'pg'
require 'pry'



ActiveRecord::Base.establish_connection(
    database: 'hospital_db',
    adapter: 'postgresql'
)

class Doctor < ActiveRecord::Base
  has_many :appointments, :skills
  has_many :patients, through: :appointments
end

class Patient < ActiveRecord::Base
  has_many :appointments
  has_many :doctors, through: :appointments
end

class Appointment < ActiveRecord::Base
  belongs_to :patient
  belongs_to :doctor
end

class Skill < ActiveRecord::Base
  belongs_to :doctor
end

binding.pry

As soon as I type ruby app.rb in my terminal I get the following errors:

/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::BASE
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of BASE was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::EXCEPTION_ALL
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of EXCEPTION_ALL was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::EXCEPTION_NaN
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of EXCEPTION_NaN was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::EXCEPTION_INFINITY
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of EXCEPTION_INFINITY was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::EXCEPTION_UNDERFLOW
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of EXCEPTION_UNDERFLOW was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::EXCEPTION_OVERFLOW
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of EXCEPTION_OVERFLOW was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::EXCEPTION_ZERODIVIDE
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of EXCEPTION_ZERODIVIDE was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::ROUND_MODE
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of ROUND_MODE was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::ROUND_UP
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of ROUND_UP was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::ROUND_DOWN
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of ROUND_DOWN was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::ROUND_HALF_UP
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of ROUND_HALF_UP was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::ROUND_HALF_DOWN
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of ROUND_HALF_DOWN was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::ROUND_CEILING
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of ROUND_CEILING was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::ROUND_FLOOR
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of ROUND_FLOOR was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::ROUND_HALF_EVEN
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of ROUND_HALF_EVEN was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::SIGN_NaN
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of SIGN_NaN was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::SIGN_POSITIVE_ZERO
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of SIGN_POSITIVE_ZERO was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::SIGN_NEGATIVE_ZERO
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of SIGN_NEGATIVE_ZERO was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::SIGN_POSITIVE_FINITE
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of SIGN_POSITIVE_FINITE was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::SIGN_NEGATIVE_FINITE
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of SIGN_NEGATIVE_FINITE was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::SIGN_POSITIVE_INFINITE
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of SIGN_POSITIVE_INFINITE was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::SIGN_NEGATIVE_INFINITE
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of SIGN_NEGATIVE_INFINITE was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::INFINITY
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of INFINITY was here
/Users/andrewkim/.rvm/gems/ruby-2.1.5@global/extensions/x86_64-darwin-14/2.1.0-static/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::NAN
/Users/andrewkim/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of NAN was here
WARN: Unresolved specs during Gem::Specification.reset:
      json (>= 1.7.7, ~> 1.7)
      minitest (~> 5.1)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
/Users/andrewkim/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.1/lib/active_record/associations/builder/association.rb:64:in `initialize': undefined method `arity' for :skills:Symbol (NoMethodError)
    from /Users/andrewkim/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.1/lib/active_record/associations/builder/collection_association.rb:18:in `initialize'
    from /Users/andrewkim/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.1/lib/active_record/associations/builder/association.rb:47:in `new'
    from /Users/andrewkim/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.1/lib/active_record/associations/builder/association.rb:47:in `create_builder'
    from /Users/andrewkim/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.1/lib/active_record/associations/builder/association.rb:35:in `build'
    from /Users/andrewkim/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.1/lib/active_record/associations.rb:1259:in `has_many'
    from app.rb:13:in `<class:Doctor>'
    from app.rb:12:in `<main>'

I imagine it's something simple, but I've tried bundle install again, and I can't figure out why its trying to override BigDecimal Constant or how I can fix it. I tried requiring activerecord and active-record but they give an easy cannot load such file error. So require active_record has got to be the right one. Any thoughts or suggestions?

Andrew Kim
  • 3,145
  • 4
  • 22
  • 42
  • It is not having any problem requiring ActiveRecord. Your first warning is an issue in the Ruby kernel, the second is a problem specifically with your Doctor class. Are you showing your entire Doctor class? – Beartech Mar 29 '15 at 20:58
  • yes, the only code I have in this directory is what I've posted except for a `schema.sql` file – Andrew Kim Mar 29 '15 at 21:03

2 Answers2

2

I'm not sure why bigdecimal is being loaded multiple times. However your Gemfile won't actually be used unless you put

require "bundler/setup"

At the top of the script.

The actual error however is because of the line

has_many :appointments, :skills

You can't list multiple associations like that - it needs to be two separate calls to has_many:

has_many :appointments
has_many :skills
Frederick Cheung
  • 83,189
  • 8
  • 152
  • 174
1

This looks wrong to me and I have tried to find a reference to it in the API:

class Doctor < ActiveRecord::Base
  has_many :appointments, :skills

The correct syntax is:

 has_many :appointments
 has_many: skills
Beartech
  • 6,173
  • 1
  • 18
  • 41
  • I think that fixed part of it. Thank you! however, it doesn't fix the warnings of the already initialized constant BigDecimal. It works now, but I don't like the ugly warning – Andrew Kim Mar 29 '15 at 21:08
  • Well, I'd say that's the correct answer then for the specific question. Were you trying to list multiple has-many relations on one line? – Beartech Mar 29 '15 at 21:09
  • I believe this might help with your warnings: http://stackoverflow.com/questions/17936340/unresolved-specs-during-gemspecification-reset – Beartech Mar 29 '15 at 21:10
  • yes, that answers it; however, any ideas as to why i'm getting the warning for BigDecimal constant being reloaded? – Andrew Kim Mar 29 '15 at 21:11
  • I tried running `bundle clean --force` I'm still getting the same warnings, and I tried the different bundle commands referenced in that post, but just get error `bundler: command not found: ` in my case active record – Andrew Kim Mar 29 '15 at 21:16
  • I'll do some research to try and get rid of the warnings, but thanks for the solution! – Andrew Kim Mar 29 '15 at 21:17
  • Ah, I don't see the bundler error listed above. Can you add it for posterity and maybe a specific answer will emerge. Also can you try starting `irb` in the same directory as your project and running the line `require 'active_record'` ? – Beartech Mar 29 '15 at 21:23
  • Also, maybe run `rvm list gemsets`. If you have "ruby-2.1.5@global" and a gemset that DOESN'T have "@global" for the same ruby version, try switching to the non-global version. i.e. `rvm gemset ruby-2.1.5-...` – Beartech Mar 29 '15 at 21:32
  • When i run `require 'active_record'` in irb in that director i get the same warnings – Andrew Kim Mar 29 '15 at 21:41