Forum: Ruby on Rails File Upload

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
2258c43182638a619920180e9e7de5bf?d=identicon&s=25 fernando (Guest)
on 2007-07-08 12:51
(Received via mailing list)

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.

Dc218395c242f9feb76c62aea1183874?d=identicon&s=25 helzer (Guest)
on 2007-07-08 14:51
(Received via mailing list)

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

2258c43182638a619920180e9e7de5bf?d=identicon&s=25 fernando (Guest)
on 2007-07-08 15:17
(Received via mailing list)

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.

Bc298d7a9345ed1f83b39afe288f5e9e?d=identicon&s=25 rob (Guest)
on 2007-07-08 16:00
(Received via mailing list)
Give attachment_fu by Rick Olson a try - it's very good and allows you
to save to the file system, database, or Amazon S3. There is also
This topic is locked and can not be replied to.