Only "form_tag" support uploading file?

Hi, there:
I wanna use plug-in “file_column” to upload image to the server. In
my test app, the view is as follow & it works well:

New entry

<%= error_messages_for 'entry' %> <% form_tag 'create', :multipart => true do -%>

Image
<%= file_column_field 'entry', 'image' %>

<%= submit_tag 'create' %> <% end -%> <%= link_to 'Back', entries_path %> =====================

However, in my real app, I scaffold and nest the resource to
RESTful, the view is as follow & it errors: “Do not know how to handle
a string with value ‘readme.jpg’ that was passed to a file_column.
Check if the form’s encoding has been set to ‘multipart/form-data’”

======================
<% form_for([@task, @comment]) do |f| %>

Comment body
<%= f.text_area :desc %>

Image
<%= file_column_field 'comment', 'image' %>

<%= f.submit button_name %>

<% end %> ======================
I checked the API doc, but seems like "form_for" does not support

option “:multipart => true”, what should I do here? Anyone could
explain me what’s differ between “form_for” & “form_tag” ??

On 14 Jan 2008, at 15:32, myst_tt wrote:

I checked the API doc, but seems like “form_for” does not support
option “:multipart => true”, what should I do here? Anyone could
explain me what’s differ between “form_for” & “form_tag” ??

It does, just pass it as the html options, ie
form_for :person, @person, :html => {:multipart => true}

The api docs on form_for are a good starting point from the difference
with form_tag.

Fred

Thanks, Frederick!

On Jan 14, 5:36 pm, Frederick C. [email protected]

Ben,
I don’t mean to be a ‘turd’ here, but that won’t work. Here is what it
should look like:
<%= form_tag(:url => {:action=> “create” }, :html => { :multipart =>
true }) -%>
Kathleen

myst_tt wrote:

New entry

<%= error_messages_for 'entry' %> <% form_tag 'create', :multipart => true do -%>

Image
<%= file_column_field 'entry', 'image' %>

<%= submit_tag 'create' %> <% end -%> <%= link_to 'Back', entries_path %> =====================

Ran into this issue just now when moving from old rails version to
2.0.2.

If you want to use form_tag instead of form_for, you must group your
action and controller hash with brackets like this:

form_tag( {:action => ‘create’}, :multipart => true ) do

Otherwise if you indicate :action with no brackets, it then thinks that
all of your parameters belong in the same hash with :action,
:controller, :params, etc. and puts everything you specify right into
the querystring. I think the above would also work without parentheses.

  • sappworks

On Fri, May 9, 2008 at 7:41 PM, [email protected]
[email protected] wrote:

I don’t mean to be a ‘turd’ here, but that won’t work. Here is what it
should look like:
<%= form_tag(:url => {:action=> “create” }, :html => { :multipart =>
true }) -%>

Rails already knows/expects the first hash will be the :url hash and
the second hash the :html.

form_tag( {:action => ‘create’}, :multipart => true ) do

I, like Ben, have long prefered the perfectly acceptable (shorter)
version you choose to criticize:

http://destiney.com/blog/rails-form-tag

-1 for failing to be a proper turd.


Greg D.
http://destiney.com/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs