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 %>

<%= category["category"] %> <%= category["created_on"].strftime("%I:%M %p %d-%b-%y") %> <%= category["updated_on"].strftime("%I:%M %p %d-%b-%y") %> <%= link_to 'Edit', :action => 'edit', :id => category%> <%= link_to 'Delete', {:action => 'destroy', :id => category}, :confirm => "Are you sure you want to delete this category?"%> <% 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

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 G. [email protected]
An: [email protected]
Betreff: [Rails] four days on rails - nil object when you didnt expect
it

Hi Peter

Thanks for that :slight_smile: Couldnt see it.

Many thanks again

Jonathan