Jonathan Gill
2006-Jun-13 13:56 UTC
[Rails] four days on rails - nil object when you didnt expect it
Hi all, Im trying to get my head around rails and to help along Im working through "four days on rails" as this seems to give a good real world example with multiple tables and relationships (the main thing I cant work out!) Ive got stuck. Some help would be really good here. The controller has this code: def list @category_pages, @categories = paginate(:category, :per_page => 10, :order_by -> ''category'') end and the view has this (just the bit thats causing the issue not all of it) <% for category in @categories %> <tr> <td><%= category["category"] %></td> <td><%= category["created_on"].strftime("%I:%M %p %d-%b-%y") %></td> <td><%= category["updated_on"].strftime("%I:%M %p %d-%b-%y") %></td> <td><%= link_to ''Edit'', :action => ''edit'', :id => category%></td> <td><%= link_to ''Delete'', {:action => ''destroy'', :id => category}, :confirm => "Are you sure you want to delete this category?"%></td> </tr> <% end %> But its throwing the error nil object when you didn''t expect it! The error occured while ecaluating nil.strftime Can someone point out the problem here? I think its right, and I guess categories is passed through with the right stuff in it, the db has the field defined, with the following data in it: +----+----------+---------------------+---------------------+ | id | category | create_on | updated_on | +----+----------+---------------------+---------------------+ | 1 | test | 2006-06-13 18:33:00 | 2006-06-13 18:33:47 | | 2 | another | 2006-06-13 18:33:00 | 2006-06-13 18:33:52 | | 3 | better | 2006-06-13 18:34:00 | 2006-06-13 18:34:43 | +----+----------+---------------------+---------------------+ Any help would be appreciated. Also any pointers to tutorials that can help me get my head around this would also be appreciated. Regards Jonathan -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 191 bytes Desc: This is a digitally signed message part Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/fb0d4f5d/attachment.bin
Peter Ertl
2006-Jun-13 14:06 UTC
[Rails] four days on rails - nil object when you didnt expect it
you got an superfluous ''d'' in ''created_on'' ''category["created_on"]'' can be written ''category.created_on'' -------- Original-Nachricht -------- Datum: Tue, 13 Jun 2006 21:56:44 +0800 Von: Jonathan Gill <jonathan.gill@securecirt.com> An: rails@lists.rubyonrails.org Betreff: [Rails] four days on rails - nil object when you didnt expect it> Hi all, > > Im trying to get my head around rails and to help along Im working > through "four days on rails" as this seems to give a good real world > example with multiple tables and relationships (the main thing I cant > work out!) > > Ive got stuck. Some help would be really good here. > > The controller has this code: > > def list > @category_pages, @categories = paginate(:category, :per_page => 10, > :order_by -> ''category'') > end > > and the view has this (just the bit thats causing the issue not all of > it) > > <% for category in @categories %> > <tr> > <td><%= category["category"] %></td> > <td><%= category["created_on"].strftime("%I:%M %p %d-%b-%y") %></td> > <td><%= category["updated_on"].strftime("%I:%M %p %d-%b-%y") %></td> > <td><%= link_to ''Edit'', :action => ''edit'', :id => category%></td> > <td><%= link_to ''Delete'', {:action => ''destroy'', :id => category}, > :confirm => "Are you sure you want to delete this > category?"%></td> > </tr> > <% end %> > > But its throwing the error nil object when you didn''t expect it! > The error occured while ecaluating nil.strftime > > Can someone point out the problem here? I think its right, and I guess > categories is passed through with the right stuff in it, the db has the > field defined, with the following data in it: > > +----+----------+---------------------+---------------------+ > | id | category | create_on | updated_on | > +----+----------+---------------------+---------------------+ > | 1 | test | 2006-06-13 18:33:00 | 2006-06-13 18:33:47 | > | 2 | another | 2006-06-13 18:33:00 | 2006-06-13 18:33:52 | > | 3 | better | 2006-06-13 18:34:00 | 2006-06-13 18:34:43 | > +----+----------+---------------------+---------------------+ > > Any help would be appreciated. > > Also any pointers to tutorials that can help me get my head around this > would also be appreciated. > > Regards > > Jonathan
Jonathan Gill
2006-Jun-13 14:29 UTC
[Rails] four days on rails - nil object when you didnt expect it
Hi Peter Thanks for that :) Couldnt see it. Many thanks again Jonathan On Tue, 2006-06-13 at 16:06 +0200, Peter Ertl wrote:> you got an superfluous ''d'' in ''created_on'' > > ''category["created_on"]'' can be written ''category.created_on'' > > > -------- Original-Nachricht -------- > Datum: Tue, 13 Jun 2006 21:56:44 +0800 > Von: Jonathan Gill <jonathan.gill@securecirt.com> > An: rails@lists.rubyonrails.org > Betreff: [Rails] four days on rails - nil object when you didnt expect it > > > Hi all, > > > > Im trying to get my head around rails and to help along Im working > > through "four days on rails" as this seems to give a good real world > > example with multiple tables and relationships (the main thing I cant > > work out!) > > > > Ive got stuck. Some help would be really good here. > > > > The controller has this code: > > > > def list > > @category_pages, @categories = paginate(:category, :per_page => 10, > > :order_by -> ''category'') > > end > > > > and the view has this (just the bit thats causing the issue not all of > > it) > > > > <% for category in @categories %> > > <tr> > > <td><%= category["category"] %></td> > > <td><%= category["created_on"].strftime("%I:%M %p %d-%b-%y") %></td> > > <td><%= category["updated_on"].strftime("%I:%M %p %d-%b-%y") %></td> > > <td><%= link_to ''Edit'', :action => ''edit'', :id => category%></td> > > <td><%= link_to ''Delete'', {:action => ''destroy'', :id => category}, > > :confirm => "Are you sure you want to delete this > > category?"%></td> > > </tr> > > <% end %> > > > > But its throwing the error nil object when you didn''t expect it! > > The error occured while ecaluating nil.strftime > > > > Can someone point out the problem here? I think its right, and I guess > > categories is passed through with the right stuff in it, the db has the > > field defined, with the following data in it: > > > > +----+----------+---------------------+---------------------+ > > | id | category | create_on | updated_on | > > +----+----------+---------------------+---------------------+ > > | 1 | test | 2006-06-13 18:33:00 | 2006-06-13 18:33:47 | > > | 2 | another | 2006-06-13 18:33:00 | 2006-06-13 18:33:52 | > > | 3 | better | 2006-06-13 18:34:00 | 2006-06-13 18:34:43 | > > +----+----------+---------------------+---------------------+ > > > > Any help would be appreciated. > > > > Also any pointers to tutorials that can help me get my head around this > > would also be appreciated. > > > > Regards > > > > Jonathan > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- Jonathan Gill +65 98551701 Chief Technology Officer +65 62436800 SecureCiRT Pte Ltd http://www.securecirt.com/ PGP : 315C 314D CD36 CBFF 728E F167 FCD8 15B7 0287 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 191 bytes Desc: This is a digitally signed message part Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/069568fc/attachment.bin