I am actually following the instructions/code snippets from “Agile Web
Development with Rails” and got as far as page 73 where I did ruby
script/generate controller Store index, then edited
store_controller.rb to
class StoreController < ApplicationController
def index
@products = Product.salable_items
end
end
and product.rb to:
def self.salable_items
find(:all,
:conditions => “date_available <= now()”,
:order => “date_available desc”)
end
but it keeps showing this error in http://localhost:3000/store/ :
NameError in StoreController#index
uninitialized constant Product
RAILS_ROOT: script/…/config/…
Application Trace | Framework Trace | Full Trace
/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in
const_missing' /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:131:in const_missing’
/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:133:in
send' /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:133:in const_missing’
app/controllers/store_controller.rb:3:in `index’
FWIW index.rhtml reads:
<% for product in @products %><td>
<img src="<%= product.image_url %>"/>
</td>
<td width="450">
<h3><%=h product.title %></h3>
<small>
<%= product.description %>
</small>
<br/>
<strong>$<%= sprintf("%0.2f", product.price) %></strong>
<%= link_to 'Add to Cart',
:action => 'add_to_cart',
:id => product %>
<br/>
</td>
<% end %>