File Upload Problems

I am obviously doing something wrong when implementing the rubyonrials
wiki code for uploading a file.

I don’t seem to be getting the actual file object included with the
form, as it complains about trying to call read on a string object.

How do I get the actual file that was uploaded?

Here is my code:

Controller

def auto
if request.post?
@sched = Schedule.new
@sched.automate(params[:schedule])
end
end

Model

def automate(schedule)
File.open(“schedule_store/#{schedule[‘filename’]}”, “w”) { |f|
f.write(schedule[‘filename’].read) }
end

View

Schedule:

I have had great success with acts_as_attachment plugin.

:ivor

Figured out how to get my file uploaded although I can’t access the
origional_filename now. This is starting to frustrate me. I don’t
really want or need all the extra stuff included in acts_as_attachment
and I have to interact with it via the commandline, RadRails hasn’t
fixed their server problem yet (been a month now) so I can’t update
plugins through Eclipse.

If anyone could help me get this working that would be fantastic.
Here is the new code which uploads the file but won’t let me get the
filename (I have to give it a generic name).

Model
def self.automate(schedule)
@file_name = “test”
schedule[:schedule_file].rewind
File.open(“schedule_store/#{@file_name}”, “w”) { |f|
f.write(schedule[:schedule_file].read) }
end

Controller
def auto
if request.post?
@sched = Schedule.automate(params[:schedule])
end
end

View
<% form_for(:schedule, @schedule, :url => {:action => ‘auto’}, :html
=> {:multipart => true}) do |form| %>

Schedule: <%= form.file_field :schedule_file %>

<%= submit_tag "Auto" %> <% end %>

Thanks,
Glen