私は続編の宝石とpostgresqlデータベースを使用しています
コードを含むhello.rbファイルがあります
require "rubygems"
require './post'
require "sequel"
# connect to an in-memory database
DB = Sequel.connect('postgres://ritesh:newpassword@localhost')
post = Post['ruby1', 'hello world1']
post[1]
テーブルポストとコードでモデルを作成しました
require 'sequel'
DB = Sequel.connect('postgres://ritesh:newpassword@localhost')
class Post < Sequel::Model
set_primary_key [:category, :title]
end
コマンド ruby hello.rb を実行すると、次のエラー hello.rb:10: undefined method `[]' for nil:NilClass (NoMethodError) が表示されます
作成について最初に知りたいことは、その名前でテーブルを作成してからモデルを作成することです?? 2番目に、最初の仮定が正しい場合、なぜこのエラーが発生するのですか??