<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Pragmatic Forums | Posts in topic 'Chapter 7.1 undefined local variable or method `product' for #&lt;StoreController:0xb73c83c4&gt;'</title>
    <link>/forums/22/topics/1672.rss</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <item>
      <title>Chapter 7.1 undefined local variable or method `product' for #&lt;StoreController:0xb73c83c4&gt; posted by Frann Leach @ Sat, 27 Dec 2008 21:59:45 +0000</title>
      <description>&lt;p&gt;I have solved this.&lt;/p&gt;


	&lt;p&gt;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.&lt;/p&gt;


	&lt;p&gt;The problem was that I had &lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;@products = product.salable_items&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;in store_controller.rb and it should have been&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;@products = Product.salable_items&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;Just a capital letter. Doh.&lt;/p&gt;</description>
      <pubDate>Sat, 27 Dec 2008 21:59:45 +0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:22:1672:7134</guid>
      <author>Frann Leach</author>
      <link>https://forums.pragprog.com/forums/22/topics/1672</link>
    </item>
    <item>
      <title>Chapter 7.1 undefined local variable or method `product' for #&lt;StoreController:0xb73c83c4&gt; posted by Frann Leach @ Sat, 27 Dec 2008 20:52:02 +0000</title>
      <description>&lt;p&gt;Ubuntu Hardy Heron&lt;br /&gt;rails 2.0.2-1ubuntu1&lt;br /&gt;ruby &amp;#8211; confusing, i seem to have both 4.1 and 1.8.6.111-2ubuntu1 installed&lt;br /&gt;rake 0.8.1-3&lt;/p&gt;


	&lt;p&gt;The book I&amp;#8217;m using is paper edition Version: 2006-2-16 (which i bought less than a month ago)&lt;/p&gt;


	&lt;p&gt;In chapter 7, i&amp;#8217;ve done all the steps, and I&amp;#8217;m getting this: &lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;NameError in StoreController#index&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;undefined local variable or method `product&amp;#8217; for #&amp;lt;storecontroller:0xb73c83c4&gt;&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;RAILS&lt;/span&gt;_ROOT: /home/tiggsy/depot&lt;br /&gt;Application Trace | Framework Trace | Full Trace&lt;/p&gt;


	&lt;p&gt;app/controllers/store_controller.rb:4:in `index&amp;#8217;&lt;/p&gt;


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


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


	&lt;p&gt;Request&lt;/p&gt;


	&lt;p&gt;Parameters:&lt;/p&gt;


	&lt;p&gt;None&lt;/p&gt;


	&lt;p&gt;Show session dump&lt;/p&gt;


	&lt;p&gt;&lt;del&gt;-&lt;/del&gt; &lt;br /&gt;:csrf_id: 5640dac78a579f37ceeb657b2f5cb1a4&lt;br /&gt;flash: !map:ActionController::Flash::FlashHash {}&lt;/p&gt;


	&lt;p&gt;Response&lt;/p&gt;


	&lt;p&gt;Headers:&lt;/p&gt;


	&lt;p&gt;{&amp;#8220;cookie&amp;#8221;=&amp;gt;[],
 &amp;#8220;Cache-Control&amp;#8221;=&amp;gt;&amp;#8221;no-cache&amp;#8221;}&lt;/p&gt;


&lt;hr /&gt;


	&lt;p&gt;I found something on here about rake, so i tried running &lt;code&gt; rake rails:freeze:edge&lt;/code&gt; and I got this:&lt;/p&gt;


	&lt;p&gt;(in /home/tiggsy/depot)&lt;br /&gt;svn: &lt;span class="caps"&gt;PROPFIND&lt;/span&gt; request failed on &amp;#8217;/svn/rails&amp;#8217;&lt;br /&gt;svn: &lt;span class="caps"&gt;PROPFIND&lt;/span&gt; of &amp;#8217;/svn/rails&amp;#8217;: could not connect to server (&lt;a href="http://dev.rubyonrails.org"&gt;http://dev.rubyonrails.org&lt;/a&gt;)&lt;br /&gt;rake aborted!&lt;br /&gt;undefined method `[]&amp;#8217; for nil:NilClass&lt;/p&gt;


	&lt;p&gt;(See full trace by running task with&amp;#8212;trace)&lt;/p&gt;


&lt;hr /&gt;


	&lt;p&gt;It doesn&amp;#8217;t solve the problem, which seems to be: undefined local variable or method `product&amp;#8217; for #&amp;lt;storecontroller:0xb73c83c4&gt; in app/controllers/store_controller.rb:4:in `index&amp;#8217;&lt;/p&gt;


	&lt;p&gt;The store_controller.rb file matches the one shown in the book:&lt;/p&gt;


&lt;code&gt;class StoreController &amp;lt; ApplicationController

  def index
    @products = product.salable_items
  end
end&lt;/code&gt;

	&lt;p&gt;and I have added&lt;/p&gt;


&lt;code&gt;def self.salable_items
  find(:all,
       :conditions =&amp;gt; "date_available &amp;lt;=now()",
       :order =&amp;gt; "date_available DESC")
end&lt;/code&gt;

	&lt;p&gt;to the product.rb file below the main validation stuff but above the protected bit.&lt;/p&gt;</description>
      <pubDate>Sat, 27 Dec 2008 20:52:02 +0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:22:1672:7133</guid>
      <author>Frann Leach</author>
      <link>https://forums.pragprog.com/forums/22/topics/1672</link>
    </item>
  </channel>
</rss>
