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. 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> 18: 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.
on 2007-03-18 03:41
on 2007-03-18 07:04
google rails file colum
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.
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 upload. 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.
on 2008-06-27 18:41
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 validations. I hope it works to you. PD: Sorry about my english, On 2 mayo, 03:52, Marcel Dohmen <rails-mailing-l...@andreas-s.net>