Forum: Ruby on Rails NoMethodError in Classified#create nil object

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ecff1c27deaec4d9c79de0dc6dadfb08?d=identicon&s=25 Tate T. (riottype)
on 2007-03-18 03:41
I'm following along the tutorials of a book (Rails Solutions: Ruby on
Rails made easy) and I've come to a part that I can't seem to figure
out. I'm trying to implement validation for file uploads (make sure
upload is a picture format).

It works fine until I upload a file that isn't an image. It should
report an error message, instead the app crashes and I get a

NoMethodError in Classified#create

Showing app/views/classified/new.rhtml where line #15 raised:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.inject

12:   <p><label for="classified_email">Email</label><br/>
13:   <%= text_field 'classified', 'email'  %></p>
14:   <p><label for="classified_category">Category</label><br />
15:   <%= collection_select(:classified, :category_id, @categories,:id,
:name) %></p>
16:   <p><label for="classified_picture">Picture</label><br />
17:   <%= file_field 'classified', 'pictureimg' %></p>

I checked my Model classified.rb against the books source code and it
matches, I also checked my classifieds controller, and new.rhmtl file
that the error references -- yet everything seems to be in order, and
the error persists.

I'm all out of ideas and could use some help.
72eb65fa089082d3bd8b38a5596ad331?d=identicon&s=25 Keynan Pratt (keynan)
on 2007-03-18 07:04
google rails file colum
Ecff1c27deaec4d9c79de0dc6dadfb08?d=identicon&s=25 Tate T. (riottype)
on 2007-03-18 22:20
Keynan Pratt wrote:
> google rails file colum

Thanks, I've bookmarked this plugin for later use - however, right now
I'm following along the tutorials of the book and I'd rather fix what I
have before I get in over my head w/ adding new features.

I'm still trying to decypher this error.
7a344051ac522edd7ffb13e8caba78b0?d=identicon&s=25 Marcel Dohmen (marceldohmen)
on 2008-05-02 10:52
As a matter a fact, the error is related to the validation itself. It
'crashes' on  the relation category-classified.
So far I found out that the error is introduced in chapter 5 after
adding the relation category-classified. It has nothing to do with file
If you remove the validations from the model it all works fine.

So far, the author hasn't come back with an answer to fix it.
Ideally, you should be able to trap the errors

Anybody got an idea how to overcome this? APparantly, the Ruby code
tries to retrieve associated records from a category, without having an
instantiated classifieds array.
538b11316de5ca31b9ae3452b799c813?d=identicon&s=25 gianpero (Guest)
on 2008-06-27 18:41
(Received via mailing list)
Hi, finally I found the solution for this problem, as Marcel Dohmen
said, the validation crashes on relation category-classified, defined
on classified.rb. just change "belongs_to :category", after all the

I hope it works to you.

PD: Sorry about my english,

On 2 mayo, 03:52, Marcel Dohmen <>
This topic is locked and can not be replied to.