Forum: Ruby on Rails file_upload ... won't

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.
Jim C. (Guest)
on 2006-03-07 11:57
(Received via mailing list)
Hi, I'm just trying out Sebastian's file_upload plugin, but I'm having
problems - bound to be my fault! I can't search gmane at the moment for
examples that I'm sure have been recently posted :-(

I have a MySQL table "scripts" with a field "filename varchar(255) not
null, and a basic scaffold'd set of files for model "Script". I've
installed file_upload using "script/plugin install", I think it caught
rev 58.

In app/models/script.rb I've added "file_column :filename", and in
app/views/scripts/_form.rhtml I've changed the generated text_field into
a file_column_field - the form looks fine, I get an Browse button. I can
use the Browse button to select a file ... but ...

When I try to submit the form, I get a crash :
 TypeError in Scripts#create

 Do not know how to handle a string with value 'jim.jpg' that was passed
 to a file_column. Check if the form's encoding has been set to
 'multipart/form-data'.

I guess I must have missed a trick somewhere else. There are no records
in the table (to be expected, but worth checking)

Where should I be looking next to figure this out?

-jim
Mikkel B. (Guest)
on 2006-03-07 12:00
(Received via mailing list)
For once thre's acutally a sane error message:

Check if the form's encoding has been set to 'multipart/form-data'.

Did you check that?


>Where should I be looking next to figure this out?
>
>-jim
>_______________________________________________
>Rails mailing list
>removed_email_address@domain.invalid
>http://lists.rubyonrails.org/mailman/listinfo/rails


Mikkel B.

www.strongside.dk    - Football Portal(DK)
nflfeed.helenius.org - Football News(DK)
ting.minline.dk      - Buy Old Stuff!(DK)
Jim C. (Guest)
on 2006-03-07 22:51
(Received via mailing list)
On Tue, Mar 07, 2006 at 09:58:56AM -0000, Mikkel B. wrote:
> For once thre's acutally a sane error message:

:-)

> Check if the form's encoding has been set to 'multipart/form-data'.
> Did you check that?

Initially no - I had incorrectly assumed that declaring file_column
would have fixed up the form definition, but I guess it can't override
what was in the template ...

So, I tried to set :multipart => true in the new.rhtml, and still had
problems.  A trawl through the docs revealed my error - where the
scaffold had created a call to start_form_tag with only one parameter,
I'd just added the :multipart to the end ... whereas the extended form
only works for me when the whole thing is fully bracketed :-

Scaffold created:
<%= start_form_tag :action => 'create' %>

I tried (and failed with):
<%= start_form_tag :action => 'create', :multipart => true %>

Everything works fine with:
<%= start_form_tag ({:action => 'create'}, {:multipart => true}) %>

-jim
This topic is locked and can not be replied to.