前提・実現したいこと
ここに質問の内容を詳しく書いてください。
ドットインストールのアクティブレコードを扱う講義(https://dotinstall.com/lessons/basic_activerecord_v2/39204)
で以下のコードを実行した際に下のエラーが出てしまいました。
実現したいことはアクティブレコードを用いてユーザの名前や年齢の情報をデータベースに挿入を行いたいです。
発生している問題・エラーメッセージ
Traceback (most recent call last): 12: from main.rb:9:in `<main>' 11: from /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_handling.rb:51:in `establish_connection' 10: from /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:1054:in `establish_connection' 9: from /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/connection_specification.rb:170:in `spec' 8: from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `require' 7: from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:291:in `load_dependency' 6: from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `block in require' 5: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' 4: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' 3: from /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:13:in `<top (required)>' 2: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_gem.rb:65:in `gem' 1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/dependency.rb:323:in `to_spec' /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/dependency.rb:313:in `to_specs': Could not find 'sqlite3' (~> 1.4) - did find: [sqlite3-1.3.13] (Gem::MissingSpecVersionError) Checked in 'GEM_PATH=/Users/haraarashi/.gem/ruby/2.6.0:/Library/Ruby/Gems/2.6.0:/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0', execute `gem env` for more information 13: from main.rb:9:in `<main>' 12: from /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_handling.rb:51:in `establish_connection' 11: from /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:1054:in `establish_connection' 10: from /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/connection_specification.rb:170:in `spec' 9: from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `require' 8: from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:291:in `load_dependency' 7: from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `block in require' 6: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require' 5: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require' 4: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `require' 3: from /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:13:in `<top (required)>' 2: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_gem.rb:65:in `gem' 1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/dependency.rb:323:in `to_spec' /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/dependency.rb:313:in `to_specs': Could not find 'sqlite3' (~> 1.4) - did find: [sqlite3-1.3.13] (Gem::MissingSpecVersionError) Checked in 'GEM_PATH=/Users/haraarashi/.gem/ruby/2.6.0:/Library/Ruby/Gems/2.6.0:/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0', execute `gem env` for more information 13: from main.rb:9:in `<main>' 12: from /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_handling.rb:51:in `establish_connection' 11: from /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:1054:in `establish_connection' 10: from /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/connection_specification.rb:170:in `spec' 9: from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `require' 8: from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:291:in `load_dependency' 7: from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `block in require' 6: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require' 5: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require' 4: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `require' 3: from /Library/Ruby/Gems/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:13:in `<top (required)>' 2: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_gem.rb:65:in `gem' 1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/dependency.rb:323:in `to_spec' /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/dependency.rb:313:in `to_specs': Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? Could not find 'sqlite3' (~> 1.4) - did find: [sqlite3-1.3.13] (LoadError) Checked in 'GEM_PATH=/Users/haraarashi/.gem/ruby/2.6.0:/Library/Ruby/Gems/2.6.0:/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0', execute `gem env` for more information
該当のソースコード
ruby
1 1 require 'active_record' 2 2 require 'pp' 3 3 require 'active_support/all' 4 4 5 5 # Timezoneの設定 6 6 Time.zone_default = Time.find_zone! 'Tokyo' 7 7 ActiveRecord::Base.default_timezone = :local 8 8 # DB情報 9 9 ActiveRecord::Base.establish_connection( 10 10 "adapter" => "sqlite3", 11 11 "database" => "./myapp.db" 12 12 ) 13 13 #usersテーブルをオブジェクトに結びつける 14 14 15 15 #ActiveRecordの継承。UsersレコードをUserクラスのインスタンスとして扱うようにする 16 16 class User < ActiveRecord::Base 17 17 end 18 18 19 19 20 20 #insert 21 21 22 22 #基本的な書き方 23 23 user = User.new 24 24 user.name = "tanaka" 25 25 user.age = 23 26 26 user.save 27 27 28 28 29 29 #応用的な書き方 30 30 user = User.new(name:"sato",age:23) 31 31 user.save 32 32 33 33 #newとsaveを同時にする書き方 34 34 User.create(name:"tanaka",age:22)``` 35 36 37### 試したこと 38 39ここに問題に対して試したことを記載してください。 40 41### 補足情報(FW/ツールのバージョンなど) 42 43ここにより詳細な情報を記載してください。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/04/11 02:09