>
> Thanks for the great book.
>
> I have been moving through the chapters and reading the forum for
> answers and the errata - however this test is stumping me.
>
> The message I get in the error is similar to a previous post titled
> "confusing error":
>
> The error is: Called id for nil, which would mistakenly be 4 -- if you
> really wanted the id of nil, use object_id
>
>
> Jarkko replied that this was bc the object had not been assigned. In
> my case that would mean what exactly?
It means the object for which you call id (maybe implicitly) is nil.
E.g.
@book = Book.find_by_id(params[:id])
@book.id
If Book.find_by_id returns nil, @book will be nil, and the second line
would raise the exception above. That's why you should generally
always make sure that a finder really returned something.
>
>
> As a note all my other tests run fine up to the point I put in this
> the get call show below:
>
> def get_book_details_for(title)
> @book = Book.find_by_title(title)
> get "/catalog/show/#{@book.id}"
> end
>
> I don't bother with the rest of the test (I increment when I have
> issues) as this line causes it to give me the error.
>
> Anyone have an idea where to look?
Please send the whole error stack, containing the line number raising
the exception. If it's the code you pasted above, my explanation above
should explain the problem fairly well.
//jarkko
--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi
Right, so @book is nil. I don't have the code or the book at hand
right now, but find the line where @book is set (in the test, the
error stack shows that the exception comes from the test, not the
actual app). It's probably something like @book =
Book.find_by_title(title), which means that you don't have a book with
the correct title in the fixtures/db.