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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
google rails file colum -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Keynan Pratt wrote:> google rails file columThanks, 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> As a matter a fact, the error is related to the validation itself. It > ''crashes'' on the relationcategory-classified. > So far I found out that the error is introduced in chapter 5 after > adding the relationcategory-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 acategory, without having an > instantiated classifieds array. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---