Antun’s Blog

Notes on OpenLaszlo, LZX and Rich Internet Application Development

Antun’s Blog header image 2

Using the form_for Method with multipart in Rails

August 22nd, 2008 · No Comments

If you’re going to upload files via an HTML form, the form’s encoding must be set to multipart/form-data. In Rails, you use a helper method to generate the form tags, so you can’t directly edit them. The preferred helper is form_for; that’s what scaffold generates.

Normally, a form_for call would look like this:


<% form_for(@entry) do |f| %>
  <!-- Form fields -->
<% end %>

To make this form be multipart, change the call to the following:


<% form_for(@entry, :html => {:multipart => true}) do |f| %>
  <!-- Form fields -->
<% end %>

Tags: Rails

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment