# Upload\_column problems on post after validation error

**URL:** <https://www.ruby-forum.com/t/upload-column-problems-on-post-after-validation-error/105332>\
**Category:** Rails\
**Created:** [May 28, 2007, 10:37pm UTC](https://www.ruby-forum.com/t/upload-column-problems-on-post-after-validation-error/105332 "2007-05-28T22:37:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gianluca\_t](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d78d45/32.png) [@gianluca\_t](https://www.ruby-forum.com/u/gianluca_t)\
**Post date:** [May 28, 2007, 10:37pm UTC](https://www.ruby-forum.com/t/upload-column-problems-on-post-after-validation-error/105332/1 "2007-05-28T22:37:15Z")

</div>

Hi to all the crew !

I’ve a little (big ?) problem.

I’m using upload\_column plugin, it works very well but it throws an  
exception when I try to repost the form after a validation error.

Here some details:

Model: (hostel.rb)

HOSTEL\_PHOTO\_DIR = Proc.new {|inst, attr| “hostel/#{inst.id}”}  
HOSTEL\_PHOTO\_THUMB = “100x100”  
HOSTEL\_PHOTO\_NORMAL = “400x400”

image\_column :photo\_1, :store\_dir =\> HOSTEL\_PHOTO\_DIR,  
:versions =\> { :thumb =\> HOSTEL\_PHOTO\_THUMB,  
:normal =\> HOSTEL\_PHOTO\_NORMAL},  
:filename =\> Proc.new {|inst, orig, ext|  
“photo\_1.#{ext}”}

View (signup\_customer.rhtml):  
\<% upload\_form\_tag :action =\> “update\_customer” do %\>  
…  
Photo 1  
\<%= upload\_column\_field “hostel”, “photo\_1” %\>  
\<% end %\>

Controller:  
def update\_customer  
begin  
…  
hostel.attributes = params[:hostel] # Where the error  
occurred…  
hostel.save!  
rescue  
@hostel = hostel  
render :action =\> “signup\_customer”  
end  
end

Now, if I post the form without validation exception, all works good !!!

But if I try to post the form without a required field I give an  
exception and the controller show the form again, if I put the required  
data and post again I receive this exception:

invalid format of ‘hostel/117/photo\_1.jpg;0182-Problemi-gravi.jpg’

|vendor/plugins/uploadcolumn/lib/upload\_column.rb:431:in `set_path' vendor/plugins/uploadcolumn/lib/upload_column.rb:809:in`send’  
vendor/plugins/uploadcolumn/lib/upload\_column.rb:809:in `photo_1_temp=' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1672:in`send’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/base.rb:1672:in  
`attributes=' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1671:in`each’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/base.rb:1671:in  
`attributes=' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations/association_proxy.rb:123:in`send’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/associations/association\_proxy.rb:123:in  
`method_missing' app/controllers/hostel_controller.rb:53:in`update\_customer’|

At line 53 in hostel\_controller.update\_customer there is the line:

```
  hostel.attributes = params[:hostel] # Where the error 

```

occurred…

I don’t know how to solve this problem !!!

Can you help me ???

Thanks in advance !!!

Tex.

---

<div class="post-metadata">

**Author:** ![gianluca\_t](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d78d45/32.png) [@gianluca\_t](https://www.ruby-forum.com/u/gianluca_t)\
**Post date:** [September 27, 2007, 11:25am UTC](https://www.ruby-forum.com/t/upload-column-problems-on-post-after-validation-error/105332/2 "2007-09-27T11:25:01Z")

</div>

That’s because it tryes to assign photo\_1\_temp before photo\_1.

This should work:  
def update\_customer  
begin  
…  
hostel.attributes = params[:hostel][:photo\_1] if  
params[:hostel][:photo\_1]  
hostel.attributes = params[:hostel] # Where the error occurred  
…  
hostel.save!  
rescue  
@hostel = hostel  
render :action =\> “signup\_customer”  
end  
end
