Wednesday 15 September 2010

ruby on rails - Is it correct to specify ":html => { :multipart => true}" for form_for? -



ruby on rails - Is it correct to specify ":html => { :multipart => true}" for form_for? -

we're running rails 3.2.19 , ruby 2.1.2.

we have legacy line of code (actually, more one, line of particular concern) reads

form_for [@commentable, @comment], :html => { :multipart => true, :class => "lightbox_form"} |f|

the form info may or may not include uploaded file @ user's discretion.

many examples in refer specifying :multipart setting, see reply @ form_for :multipart => true spits out , in looking @ docs @ http://guides.rubyonrails.org/v3.2.19/form_helpers.html#uploading-files, see shouldn't necessary (except if using form_tag). see give-and-take @ https://github.com/rails/rails/issues/10176 adds confusion.

i'm asking in part because we're getting eof errors in rack (no content coming through on multipart parser; see rack throwing eoferror (bad content body) if you're interested in details).

our code may have been run under before versions of rails when may have been necessary (and may holdover). given other examples on include :multipart, want improve understand if or when :multipart needed form_for before remove , side effects may encounter.

it's not required in rails 3.1 , later, long you're using form_for file_field this:

<%= form_for @person |f| %> <%= f.file_field :picture %> <% end %>

this not work:

<%= form_for @person |f| %> <%= file_field_tag 'person[picture]' %> <% end %>

you can verify it's working. inspect generated html , enctype="multipart/form-data" attribute on form tag. rails doesn't magic beyond setting encoding type, if attribute there, you're good.

ruby-on-rails ruby rack form-for multipart-form

No comments:

Post a Comment