I’m new to Ruby and to fairly new to programming. I’ve been working
through the “Agile Web D. with Rails” book, and I’m stuck on
page
73 of the print version. The book’s online errata directed me here with
my
questions.
I’m running Ruby 1.8.3 with MySQL 4.1.8 on OSX 10.3.9. I’ve created the
scaffolding for Admin controller and entered three sample products. I
typed the examples to build the Store controller carefully and finally
just copied them from what the book’s Web site supplies. So now I have:
app/controllers/store_controller.rb>
class StoreController < ApplicationController
def index
@products = Product.salable_items
end
end
and in the app/models/product.rb I have the new piece of code
snip
def self.salable_items
find(:all,
:conditions => “date_available <= now()”,
:order => “date_available desc”)
end
_end snip
When I try to access the store page, it returns:
Couldn’t find Product with ID=all AND date_available <= now()
/app/models/product.rb:21:in salable_items' app/controllers/store_controller.rb:4:in
index’
script/server:48
When I connect with the admin controller, I see the following in the
mysql
connection logs that I set up:
060227 21:22:09 2 Connect root@localhost on depot_development
2 Query SELECT * FROM products
2 Query SHOW FIELDS FROM products
When I connect with the store controller, I see:
060227 21:23:02 3 Connect root@localhost on depot_development
3 Query SELECT * FROM products WHERE id =
‘—
:all’ AND date_available <= now() LIMIT 1
So it is connecting to the database, but id = ‘— :all’ isn’t a
meaningful id number. Thing is, I don’t really understand how or why the
find() function and :all produces that . . .
Any help would be greatly appreciated!
Thanks in advance,
Melissa