|
|
|
@ -5,7 +5,7 @@ class Fruit
|
|
|
|
else
|
|
|
|
else
|
|
|
|
DB = PG.connect(host: "localhost", port: 5432, dbname: 'simplerails')
|
|
|
|
DB = PG.connect(host: "localhost", port: 5432, dbname: 'simplerails')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def initialize(opts = {})
|
|
|
|
def initialize(opts = {})
|
|
|
|
@id = opts["id"].to_i
|
|
|
|
@id = opts["id"].to_i
|
|
|
|
@name = opts["name"]
|
|
|
|
@name = opts["name"]
|
|
|
|
@ -22,4 +22,9 @@ class Fruit
|
|
|
|
results = DB.exec("SELECT * FROM fruits WHERE id=#{id};")
|
|
|
|
results = DB.exec("SELECT * FROM fruits WHERE id=#{id};")
|
|
|
|
return Fruit.new(results.first)
|
|
|
|
return Fruit.new(results.first)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def self.create(opts={})
|
|
|
|
|
|
|
|
results = DB.exec("INSERT INTO fruits (name, color, readytoeat) VALUES ( '#{opts["name"]}', '#{opts["color"]}', #{opts["readyToEat"]} );")
|
|
|
|
|
|
|
|
return Fruit.new(opts)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|