# Validating to see if item can be destroyed

**URL:** <https://www.ruby-forum.com/t/validating-to-see-if-item-can-be-destroyed/129005>\
**Category:** Rails\
**Created:** [February 13, 2008, 2:14pm UTC](https://www.ruby-forum.com/t/validating-to-see-if-item-can-be-destroyed/129005 "2008-02-13T14:14:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramontayag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c6cbf5/32.png) [@ramontayag](https://www.ruby-forum.com/u/ramontayag)\
**Post date:** [February 13, 2008, 2:14pm UTC](https://www.ruby-forum.com/t/validating-to-see-if-item-can-be-destroyed/129005/1 "2008-02-13T14:14:29Z")

</div>

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](http://pastie.caboo.se/151482)

I’m stumped :o

## Thanks,

Ramon T.

---

<div class="post-metadata">

**Author:** ![ramontayag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c6cbf5/32.png) [@ramontayag](https://www.ruby-forum.com/u/ramontayag)\
**Post date:** [February 13, 2008, 3:25pm UTC](https://www.ruby-forum.com/t/validating-to-see-if-item-can-be-destroyed/129005/2 "2008-02-13T15:25:13Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hey all. I think I flooded #rubyonrails too much I’m not getting  
> replies anymore… hehe.

–  
Ramon T.

---

<div class="post-metadata">

**Author:** ![ramontayag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c6cbf5/32.png) [@ramontayag](https://www.ruby-forum.com/u/ramontayag)\
**Post date:** [February 15, 2008, 3:34am UTC](https://www.ruby-forum.com/t/validating-to-see-if-item-can-be-destroyed/129005/3 "2008-02-15T03:34:12Z")

</div>

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  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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 T.
