Forum: Ruby on Rails rescue problem and attachment_fu

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Pawel J. (Guest)
on 2007-07-10 18:01
Hello

I have a following method in my image controller. It should add images
to existing gallery.

 def create

 Image.transaction do
 begin
 params[:images].collect { |image| @gallery.images <<
Image.new(:uploaded_data => image) }
 redirect_to admin_gallery_url(@gallery)
 rescue ActiveRecord::RecordInvalid
 render admin_gallery_url(@gallery)
 end
 end unless params[:images].nil?

 end

I am using attachment_fu as my image plugin. It works fine, except i
can't see validation errors. Validation WORKS because wrong files do not
get saved in a database. I am also making a transaction since
params[:images] is an array of file elements so i want to save all or
nothing. I am trying to use rescue to render a template so i can see
validation errors but it doesn't work.(like it doesnt care about rescue)
I am a begginer, is this the right way to go with this problem? and why
doesn't this work :)

In my image model i have ofcourse
validates_as_attachment
This topic is locked and can not be replied to.