File Upload


I’m still quite new to RoR and I am having trouble uploading files to
a file system. I have been following this tutorial: :
1.2.1. The simplest thing that could possibly work

But when I try to save a file I get “You have a nil object when you
didn’t expect it!
The error occurred while evaluating”
In this very simple example its the controller that does all the work:

def save"#{RAILS_ROOT}/public/images/testWorked.jpg", “wb”) do |

Why is my @params[‘picture_file’] object empty?

Any assistance would be much appreciated.



If these images are coming from a browser, they need to have multi-
part encoding. Then, you’ll need Ruby code to decode this.

Why don’t you use some complete plugin such as acts_as_attachment or



Thanks for the reply,

I want to save the files to the file system and not to a database. fto
set the enctype I used multipart => true and the html output is set to
enctype=“multipart/form-data” so that should be fine.
Is the ruby code:"#{RAILS_ROOT}/public/images/testWorked.jpg", “wb”) do |

incorrect for dealing with file uploads?

I’ll see if i can find a plugin that allows saves to the file system.


Give attachment_fu by Rick O. a try - it’s very good and allows you
to save to the file system, database, or Amazon S3. There is also

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