Hey all. I think I flooded #rubyonrails too much I''m not getting replies anymore.. hehe. Let''s say I have two models: Idea and IdeaImage. Idea has_many :idea_images and IdeaImage belongs_to :idea. Here''s my question: how do I allow deletion _only if_ there is more than 1 idea_image left in idea? Here are the different scenarios I''ve tried: http://pastie.caboo.se/151482 I''m stumped :o Thanks, -- Ramon Tayag --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ramon Miguel M. Tayag
2008-Feb-13 14:24 UTC
Re: Validating to see if item can be destroyed
Ok, super weird... I put a debugger: def validate_as_destroyable debugger if idea.idea_images.size <= 1 return false end end in the debugger i type idea. it works. i type idea.idea_images. it works. in my log i still get the same error though... NoMethodError (You have a nil object when you didn''t expect it! The error occurred while evaluating nil.idea_images): /app/models/idea_image.rb:25:in `validate_as_destroyable'' On Feb 13, 2008 9:14 PM, Ramon Miguel M. Tayag <ramon.tayag-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey all. I think I flooded #rubyonrails too much I''m not getting > replies anymore.. hehe.-- Ramon Tayag --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ramon Miguel M. Tayag
2008-Feb-15 02:33 UTC
Re: Validating to see if item can be destroyed
I''ve fallen into this trap SO MANY times before... It was failing because I was using attachment_fu and the thumbnails'' idea_id were nil. Ugh.. sorry for wasting your time (and mine, haha!) On Wed, Feb 13, 2008 at 10:24 PM, Ramon Miguel M. Tayag <ramon.tayag-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ok, super weird... I put a debugger: > > def validate_as_destroyable > debugger > if idea.idea_images.size <= 1 > return false > end > end > > in the debugger i type idea. it works. i type idea.idea_images. it > works. in my log i still get the same error though... > > NoMethodError (You have a nil object when you didn''t expect it! > The error occurred while evaluating nil.idea_images): > /app/models/idea_image.rb:25:in `validate_as_destroyable''-- Ramon Tayag --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---