Forum: Ruby on Rails four days on rails - nil object when you didnt expect it

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.
Jonathan Gill (Guest)
on 2006-06-13 15:57
(Received via mailing list)
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
Peter Ertl (Guest)
on 2006-06-13 16:07
(Received via mailing list)
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
Jonathan Gill (Guest)
on 2006-06-13 16:30
(Received via mailing list)
Hi Peter

Thanks for that :)  Couldnt see it.

Many thanks again

Jonathan
This topic is locked and can not be replied to.