Newbie: Can't get file to upload

Since I can’t get the fancy upload progress thing to work, I thought
that I would revert back to a regular file upload scenario.

I have a very simple file upload form set up. It appears that my file
parameter is coming into the controller as a string, not a file object.

Here’s my view:

<%= form_tag :action => ‘save_HTML’,
:multipart => ‘true’ %>
<%= file_field ‘eSimplyJob’, ‘file’ %>

<%= submit_tag "Upload" %>

<%= end_form_tag %>

Here’s my controller method:

public
def save_HTML
@filename = @params[:eSimplyJob][:file].original_filename
File.open("#{RAILS_ROOT}/htmlfiles/#{@filename}", “wb”) do |f|
f.write(@params[:eSimplyJob][:file].read)
end
puts “Finished with save_HTML”
end

When I execute the upload, I get the following error:

undefined method `original_filename’ for “upload.rhtml”:String

I understand that this means that @params[:eSimplyJob][:file] is a
String and not an IO object.

What am I doing wrong?

Thanks for any help.

Wes G.

Well, I feel dumb.

I’ve decided to be very explicit about function call parens and the hash
specifications for parameters.

Doing this:

<%= form_tag ({ :action => ‘save_HTML’ },
{ :multipart => ‘true’ }) %>

works fine.

Thanks,
Wes

Wes G. wrote:

Since I can’t get the fancy upload progress thing to work, I thought
that I would revert back to a regular file upload scenario.

I have a very simple file upload form set up. It appears that my file
parameter is coming into the controller as a string, not a file object.

Here’s my view:

<%= form_tag :action => ‘save_HTML’,
:multipart => ‘true’ %>
<%= file_field ‘eSimplyJob’, ‘file’ %>

<%= submit_tag "Upload" %>

<%= end_form_tag %>

Here’s my controller method:

public
def save_HTML
@filename = @params[:eSimplyJob][:file].original_filename
File.open("#{RAILS_ROOT}/htmlfiles/#{@filename}", “wb”) do |f|
f.write(@params[:eSimplyJob][:file].read)
end
puts “Finished with save_HTML”
end

When I execute the upload, I get the following error:

undefined method `original_filename’ for “upload.rhtml”:String

I understand that this means that @params[:eSimplyJob][:file] is a
String and not an IO object.

What am I doing wrong?

Thanks for any help.

Wes G.

Hey Wes,
Can you help me if I ask you to make the uploading restricted to only
doc files?
Since you are half way already, I think you’ll be able to guess what I
am talking about.
Thanks in advance.