Forum: Ruby on Rails How do I fix this? Power went down.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8c0b00d9715d7d5d4792134599fe4232?d=identicon&s=25 eengnerd (Guest)
on 2009-04-06 21:09
(Received via mailing list)
I was successful in reaching page 184 in the book "Agile Web
Development with Rails" 3rd edition and while running the website with
PostGreSQL as the backend, the power went down.  The PostGreSQL
database contents look OK and so do the source code files I was
editing.  But whenever I click on any "Add To Cart" button in the
catalog, I get the following information in the terminal window where
the "script/server" command was issued.  By the way, I'm using
Mongrel, not Webrick.

Processing StoreController#add_to_cart (for 127.0.0.1 at 2009-04-06
11:49:15) [POST]
  Parameters: {"commit"=>"Add to Cart",
"authenticity_token"=>"2hiFEqPkmMUXAZnTJ6jN4TKkMagLt0BY0W/M6fJj1+w=",
"id"=>"1"}
  Product Load (1.0ms)   SELECT * FROM "products" WHERE
("products"."id" = 1)

NoMethodError (You have a nil object when you didn't expect it!
The error occurred while evaluating nil.add_product):
  app/controllers/store_controller.rb:9:in `add_to_cart'
  /usr/lib/ruby/1.8/mongrel.rb:159:in `process_client'
  /usr/lib/ruby/1.8/mongrel.rb:158:in `each'
  /usr/lib/ruby/1.8/mongrel.rb:158:in `process_client'
  /usr/lib/ruby/1.8/mongrel.rb:285:in `run'
  /usr/lib/ruby/1.8/mongrel.rb:285:in `initialize'
  /usr/lib/ruby/1.8/mongrel.rb:285:in `new'
  /usr/lib/ruby/1.8/mongrel.rb:285:in `run'
  /usr/lib/ruby/1.8/mongrel.rb:268:in `initialize'
  /usr/lib/ruby/1.8/mongrel.rb:268:in `new'
  /usr/lib/ruby/1.8/mongrel.rb:268:in `run'

Rendered rescues/_trace (72.4ms)
Rendered rescues/_request_and_response (0.8ms)
Rendering rescues/layout (internal_server_error)

I really don't want to lose all my work, but I'm totally lost on how
to fix this problem.

Sincerely,

Arthur
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-04-06 21:35
(Received via mailing list)
If you cannot see why the object at line 9 in store_controller.rb is nil
then now is your chance to learn about ruby-debug.  Have a look and see
what
is happening.  (I don't know the answer).

2009/4/6 eengnerd <eengnerd@yahoo.com>
8c0b00d9715d7d5d4792134599fe4232?d=identicon&s=25 eengnerd (Guest)
on 2009-04-06 21:41
(Received via mailing list)
Nice idea, but I don't have any books or tutorials on that...don't
even know how to start the debugger.

Arthur
8c0b00d9715d7d5d4792134599fe4232?d=identicon&s=25 eengnerd (Guest)
on 2009-04-06 21:47
(Received via mailing list)
OK, got ruby-debug installed and issued the command: script/server -u
Got running in debug mode.  No more info than before.  Now what?

Arthur
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2009-04-06 21:48
eengnerd wrote:
> Nice idea, but I don't have any books or tutorials on that...don't
> even know how to start the debugger.
>
> Arthur

A quick Web search on the subject would give you the answer.  (FWIW, I
was equally unenlightened about the debugger till about 2 days ago.)

Best,
--
Marnen Laibow-Koser
marnen@marnen.org
http://www.marnen.org
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-04-06 21:50
(Received via mailing list)
There are lots of tutorials. Also look at the rails guides and
railscasts. I
can't point to them off the top of my head but I am sure google will
find
them.

2009/4/6 eengnerd <eengnerd@yahoo.com>
4c438a80fc30661ad619ea177cf9cbd0?d=identicon&s=25 Freddy Andersen (Guest)
on 2009-04-06 22:36
(Received via mailing list)
Does this line produce a product?

Product Load (1.0ms)   SELECT * FROM "products" WHERE
("products"."id" = 1)
8c0b00d9715d7d5d4792134599fe4232?d=identicon&s=25 eengnerd (Guest)
on 2009-04-06 22:59
(Received via mailing list)
Obviously not in the estimation of the mongrel server and interacting
code, but the database records are there and the id does exist.

Arthur
8c0b00d9715d7d5d4792134599fe4232?d=identicon&s=25 eengnerd (Guest)
on 2009-04-06 23:14
(Received via mailing list)
I tried dropping ALL the tables in the PostGreSQL database and running
rake db:migrate again.  This results in the very same error messages
as before.  As the system was running successfully before the power
outage, I'm of the opinion that there is something else going on
here...perhaps there's a way to recompile all of the ruby source
files?

Arthur
Fed972732accd37c4cf1fb56dbfe1405?d=identicon&s=25 Hugh Themm (hughthemm)
on 2009-04-07 16:04
(Received via mailing list)
You need to show your controller or view.

I seriously doubt something went that wrong with ruby, but an apt-get
should work just fine to re-install.

-ht
D877dec36ab3027ff7c9016e83cc1a4f?d=identicon&s=25 Jack Bauer (realmadrid2727)
on 2009-04-07 17:39
This feels like a mistyped variable to me. Post the controller code for
that action though, it's probably a very simple little solution.
4c438a80fc30661ad619ea177cf9cbd0?d=identicon&s=25 Freddy Andersen (Guest)
on 2009-04-07 18:21
(Received via mailing list)
Lets have a look at your store controller...

The nil happens here app/controllers/store_controller.rb:9:in
`add_to_cart'
This topic is locked and can not be replied to.