fruit index gets with postgres

master
Matt Huntington 8 years ago
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…
Cancel
Save