parent
c20ce738af
commit
d5558fc2ee
@ -1,9 +1,15 @@
|
|||||||
class Fruit
|
class Fruit
|
||||||
|
DB = PG.connect(host: "localhost", port: 5432, dbname: 'simplerails')
|
||||||
|
|
||||||
|
def initialize(opts = {})
|
||||||
|
@id = opts["id"].to_i
|
||||||
|
@name = opts["name"]
|
||||||
|
@color = opts["color"]
|
||||||
|
@readyToEat = (opts["readytoeat"]=='t')?true:false
|
||||||
|
end
|
||||||
|
|
||||||
def self.all
|
def self.all
|
||||||
[
|
results = DB.exec("SELECT * FROM fruits;")
|
||||||
{ name: 'apple', color: 'red', readyToEat: true },
|
return results.map { |fruit_opts| Fruit.new(fruit_opts)}
|
||||||
{ name: 'banana', color: 'yellow', readyToEat: false },
|
|
||||||
{ name: 'orange', color: 'orange', readyToEat: false }
|
|
||||||
]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in new issue