views:

108

answers:

2

I had a working code for Rails 2 to handle file uploads that no longer works with Rails 3. The code is:

# Handling file uploads
def file=(file_data)
  unless file_data.blank?
    @file_data = file_data
    self.filename = file_data.original_filename
    self.size_before = file_data.size
  end
end

Now Rails 3 doesn't like that, complains with:

undefined method `original_filename' for "MyFile.Ext":String

Any solutions that doesn't involve using a file attachment handler (Paperclip, etc)?

A: 

Obviously, 'file_data' is a different type than in your old environment. Here it's a String (which doesn't respond to 'original_filename'), but in your Rails 2 app it could have been StringIO.

Try figuring how rails 3 handles binary data when posting a form by looking in your logs for params and/or debugging and investigating input in your receiving controller action.

Provide more context for more precise answers ;-)

Jeppe Liisberg
Hi, I'm curious as to whether my answer was of any help to you. If not, you can provide me with complete steps and code to reproduce the problem, and I'll see if I can help :-)
Jeppe Liisberg
The problem was the form was not multipart :)
Omar
You should add that as an answer and accept it.
The Doctor What
A: 

The problem was that the form wasn't a multipart form.

Omar