2006-04-25

I was using file_column today in Ruby on Rails and ended up with the error:

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

The problem is obvious.. enctype="multipart/form-data" was not part of the form_tag.

Now how to get that to work.. not so easy. Rails manual might make you think you should do something like:

<%= start_form_tag :action => 'create', :multipart => true %>

Nope.. doesn't work the way it should.. so what do you try next?

<%= start_form_tag { :action => 'create' }, :multipart => true %>

No.

<%= start_form_tag { :action => 'create' }, { :multipart => true } %>

Still doesn't work.

Try this:

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

For your edit screens use:

<%= start_form_tag ( {:action => 'update', :id => @product }, :multipart => true ) %>

16 Responses to “multipart in start_form_tag”

  1. joeee Says:

    Thanks, saved me today.

  2. mrpete Says:

    many thanks for :-
    'update', :id => @product }, :multipart => true ) %>

    works perfectly and saved me a lot of time.
    Many thanks again!

  3. chris Says:

    Many many thanks for the tip. You really bailed me out!

  4. victor Says:

    thanks, I was having the same problem!

  5. Matze Says:

    half a year later it caught me too... ;-)

    Thanks

  6. Mulasse Says:

    Thx, i've been looking for it for a while

  7. bbb Says:

    Thx so much, was like a panadol for my head.

  8. Adventures on Rails :: Problems with file_upload solved Says:

    [...] ; true) especially the exact using of the parentheses is important. This one saved my day: http://ifakedit.com/log/2006/04/25/multipart-in-start_form_tag/ [...]

  9. Adventures on Rails :: Problems with file_upload solved Says:

    [...] ; true) especially the exact using of the parentheses is important. This one saved my day: http://ifakedit.com/log/2006/04/25/multipart-in-start_form_tag/ [...]

  10. Julian Schrader Says:

    Thanks, you just saved my arse ;-)

  11. dogcow Says:

    Yes, this was very helpful, thank you.
    It's even more difficult if you want to make it work on a page with several forms. Then you need to do it like:

    start_form_tag( {:action => 'myaction'}, {:id=>'42', :name=>'myformname', :multipart => true } )

    ...and woe betide you if you don't get all of the parentheses right... what's even worse is that I haven't managed yet to get this to work with the non-deprecated version .

  12. Mike Says:

    THANK YOU !!!!!!!

  13. aageboi Says:

    How can I do that with , I just try many ways to make this right (silly question isn't it? :D)

    thanks a lot

  14. aageboi Says:

    How can I do that with 'form for' not 'start form tag', I just try many ways to make this right (silly question isn’t it? :D)

    thanks a lot

  15. matt collins Says:

    Thanks for the post. Just what I was looking for.

    aageboi:

    The form_for version would be something like this:

    products_path, :html => { :multipart => true } do |f| -%>

    (the critical bit is the :html => {:id => 'person_form'})

  16. James Watts Says:

    I try do do that with form_remote_tag .... how i can do that??

Leave a Reply