# Rescue ActiveRecord::RecordInvalid

**URL:** <https://www.ruby-forum.com/t/rescue-activerecord-recordinvalid/159006>\
**Category:** Rails\
**Created:** [January 30, 2009, 10:38am UTC](https://www.ruby-forum.com/t/rescue-activerecord-recordinvalid/159006 "2009-01-30T10:38:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![petan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@petan](https://www.ruby-forum.com/u/petan)\
**Post date:** [January 30, 2009, 10:38am UTC](https://www.ruby-forum.com/t/rescue-activerecord-recordinvalid/159006/1 "2009-01-30T10:38:00Z")

</div>

Hi all,

I am using is\_attachment plugin, but I will always end up with this  
error:

RuntimeError in PostsController#create  
BLAH

which was caused by:

version.filename = file\_name\_for\_version(version\_name)  
begin  
version.save!  
rescue ActiveRecord::RecordInvalid  
raise “BLAH”  
end  
end

RecordInvalid was raised by save! because is invalid.  
Does anyone know why? I am uploading an image so it should validate  
fine.

Any help would be most welcome

---

<div class="post-metadata">

**Author:** ![petan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@petan](https://www.ruby-forum.com/u/petan)\
**Post date:** [January 30, 2009, 10:43am UTC](https://www.ruby-forum.com/t/rescue-activerecord-recordinvalid/159006/2 "2009-01-30T10:43:20Z")

</div>

Hi Petan,

That’s clearly not enough code to help you. What are the validations  
on you version model?

Besides that it’s good practice to not user save! but only save.

ciao, tom

On Jan 30, 10:38 am, Petan C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![petan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@petan](https://www.ruby-forum.com/u/petan)\
**Post date:** [January 30, 2009, 10:52am UTC](https://www.ruby-forum.com/t/rescue-activerecord-recordinvalid/159006/3 "2009-01-30T10:52:47Z")

</div>

Hi Tom,

thx for your super quick reply.

is\_attachment :image\_engine =\> :rmagick, :image\_versions =\> { :small =\>  
{ :cropper =\> [230,230] }}, :validate =\> {:min\_width =\> 230, :min\_height  
=\> 230, :content\_type =\> :image }

Cheers,  
P.
