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)?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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 ;-)

2 Comments

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 :-)
The problem was the form was not multipart :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.