Search code examples
ruby-on-railsrubytemporary-files

rails3, confused about using params[:filename].tempfile.path vs params[:filename][:tempfile].path


On a Rails 3 app hosted at Heroku, where a multipart file is POSTed to my app, I'm trying to use some sample code that says :

File.open(params['filename'][:tempfile].path)

however, my logs show the error NoMethodErr no such method as tempfile.

I also tried

File.open(params[:filename].tempfile.path)

got the same error.

I added require 'tempfile' to my Controller, made no difference.


Solution

  • When a file is posted to your application, the object in the params should already be a Tempfile so calling [:tempfile] or .tempfile should not be necessary. Try something like this:

    File.open params[:filename].path