small medium large xlarge

Generic-user-small
27 Dec 2008, 20:52
Frann Leach (2 posts)

Ubuntu Hardy Heron rails 2.0.2-1ubuntu1 ruby - confusing, i seem to have both 4.1 and 1.8.6.111-2ubuntu1 installed rake 0.8.1-3

The book I’m using is paper edition Version: 2006-2-16 (which i bought less than a month ago)

In chapter 7, i’ve done all the steps, and I’m getting this:

NameError in StoreController#index

undefined local variable or method `product’ for #

RAILS_ROOT: /home/tiggsy/depot Application Trace | Framework Trace | Full Trace

app/controllers/store_controller.rb:4:in `index’

vendor/rails/actionpack/lib/action_controller/base.rb:1158:in send' vendor/rails/actionpack/lib/action_controller/base.rb:1158:in perform_action_without_filters’ vendor/rails/actionpack/lib/action_controller/filters.rb:697:in call_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:689:in perform_action_without_benchmark’ vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:in measure’ vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue' vendor/rails/actionpack/lib/action_controller/rescue.rb:199:in perform_action_without_caching’ vendor/rails/actionpack/lib/action_controller/caching.rb:678:in perform_action' vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in cache’ vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in cache' vendor/rails/actionpack/lib/action_controller/caching.rb:677:in perform_action’ vendor/rails/actionpack/lib/action_controller/base.rb:524:in send' vendor/rails/actionpack/lib/action_controller/base.rb:524:in process_without_filters’ vendor/rails/actionpack/lib/action_controller/filters.rb:685:in process_without_session_management_support' vendor/rails/actionpack/lib/action_controller/session_management.rb:123:in process’ vendor/rails/actionpack/lib/action_controller/base.rb:388:in process' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:171:in handle_request’ vendor/rails/actionpack/lib/action_controller/dispatcher.rb:115:in dispatch' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:126:in dispatch_cgi’ vendor/rails/actionpack/lib/action_controller/dispatcher.rb:9:in dispatch' vendor/rails/railties/lib/webrick_server.rb:112:in handle_dispatch’ vendor/rails/railties/lib/webrick_server.rb:78:in service' /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in service’ /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in run' /usr/lib/ruby/1.8/webrick/server.rb:173:in start_thread’ /usr/lib/ruby/1.8/webrick/server.rb:162:in start' /usr/lib/ruby/1.8/webrick/server.rb:162:in start_thread’ /usr/lib/ruby/1.8/webrick/server.rb:95:in start' /usr/lib/ruby/1.8/webrick/server.rb:92:in each’ /usr/lib/ruby/1.8/webrick/server.rb:92:in start' /usr/lib/ruby/1.8/webrick/server.rb:23:in start’ /usr/lib/ruby/1.8/webrick/server.rb:82:in start' vendor/rails/railties/lib/webrick_server.rb:62:in dispatch’ vendor/rails/railties/lib/commands/servers/webrick.rb:66 /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require' /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in require’ vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in require' vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in new_constants_in’ vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in require' vendor/rails/railties/lib/commands/server.rb:39 script/server:3:in require’ script/server:3

app/controllers/store_controller.rb:4:in index' vendor/rails/actionpack/lib/action_controller/base.rb:1158:in send’ vendor/rails/actionpack/lib/action_controller/base.rb:1158:in perform_action_without_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:697:in call_filters’ vendor/rails/actionpack/lib/action_controller/filters.rb:689:in perform_action_without_benchmark' vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue’ /usr/lib/ruby/1.8/benchmark.rb:293:in measure' vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue’ vendor/rails/actionpack/lib/action_controller/rescue.rb:199:in perform_action_without_caching' vendor/rails/actionpack/lib/action_controller/caching.rb:678:in perform_action’ vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in cache' vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in cache’ vendor/rails/actionpack/lib/action_controller/caching.rb:677:in perform_action' vendor/rails/actionpack/lib/action_controller/base.rb:524:in send’ vendor/rails/actionpack/lib/action_controller/base.rb:524:in process_without_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:685:in process_without_session_management_support’ vendor/rails/actionpack/lib/action_controller/session_management.rb:123:in process' vendor/rails/actionpack/lib/action_controller/base.rb:388:in process’ vendor/rails/actionpack/lib/action_controller/dispatcher.rb:171:in handle_request' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:115:in dispatch’ vendor/rails/actionpack/lib/action_controller/dispatcher.rb:126:in dispatch_cgi' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:9:in dispatch’ vendor/rails/railties/lib/webrick_server.rb:112:in handle_dispatch' vendor/rails/railties/lib/webrick_server.rb:78:in service’ /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in service' /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in run’ /usr/lib/ruby/1.8/webrick/server.rb:173:in start_thread' /usr/lib/ruby/1.8/webrick/server.rb:162:in start’ /usr/lib/ruby/1.8/webrick/server.rb:162:in start_thread' /usr/lib/ruby/1.8/webrick/server.rb:95:in start’ /usr/lib/ruby/1.8/webrick/server.rb:92:in each' /usr/lib/ruby/1.8/webrick/server.rb:92:in start’ /usr/lib/ruby/1.8/webrick/server.rb:23:in start' /usr/lib/ruby/1.8/webrick/server.rb:82:in start’ vendor/rails/railties/lib/webrick_server.rb:62:in dispatch' vendor/rails/railties/lib/commands/servers/webrick.rb:66 /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require’ /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in require' vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in require’ vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in new_constants_in' vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in require’ vendor/rails/railties/lib/commands/server.rb:39 script/server:3:in `require’ script/server:3

Request

Parameters:

None

Show session dump


:csrf_id: 5640dac78a579f37ceeb657b2f5cb1a4 flash: !map:ActionController::Flash::FlashHash {}

Response

Headers:

{“cookie”=>[], “Cache-Control”=>”no-cache”}


I found something on here about rake, so i tried running ` rake rails:freeze:edge` and I got this:

(in /home/tiggsy/depot) svn: PROPFIND request failed on ‘/svn/rails’ svn: PROPFIND of ‘/svn/rails’: could not connect to server (http://dev.rubyonrails.org) rake aborted! undefined method `[]’ for nil:NilClass

(See full trace by running task with –trace)


It doesn’t solve the problem, which seems to be: undefined local variable or method product' for #<StoreController:0xb73c83c4> in app/controllers/store_controller.rb:4:in index’

The store_controller.rb file matches the one shown in the book:

`class StoreController < ApplicationController

def index @products = product.salable_items end end`

and I have added

def self.salable_items find(:all, :conditions => "date_available <=now()", :order => "date_available DESC") end

to the product.rb file below the main validation stuff but above the protected bit.

Generic-user-small
27 Dec 2008, 21:59
Frann Leach (2 posts)

I have solved this.

The rake thing I did was not needed, and screwed up my installation, so that I had to copy the vendor information from the demo project. Before I did that, even with reinstalls of all components, webrick would not open, as there were files and such missing.

The problem was that I had

@products = product.salable_items

in store_controller.rb and it should have been

@products = Product.salable_items

Just a capital letter. Doh.

You must be logged in to comment