Ruby on Rails: Server error with while trying to upload a file using attachment_fu: (can't convert nil into Integer)

StackOverflow https://stackoverflow.com/questions/5335557

Question

I followed a simple example to upload a file (see link to code below). When i add to the upload form the field <%= f.file_field :uploaded_data %>, and click submit button on the form (with or without a a file attachment), i get an error message in the web page: 500 Internal Server Error

On the server log i get an error message:TypeError (can't convert nil into Integer):

I am on rails 3.0.5, Ruby 1.9.2, Windows 7

I used the sample code at:http://clarkware.com/blog/2007/02/24/file-upload-fu

Below you will find a print out of the server log:

Rendered mugshot/new.html.erb within layouts/application (10.0ms)
Completed 200 OK in 289ms (Views: 49.0ms | ActiveRecord: 0.0ms)
Error during failsafe response: ActionView::Template::Error
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/whiny_nil.rb:48:in `method_missing'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_dispatch/http/parameters.rb:10:in `parameters'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb:3:in `_c___uby____
lib_ruby_gems_______gems_actionpack_______lib_action_dispatch_middleware_templates_rescues_diagnostics_erb___637362275_26463528_704965928'

  c:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_view/template.rb:135:in `block in render'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/notifications.rb:54:in `instrument'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_view/template.rb:127:in `render'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_view/render/rendering.rb:59:in `block in _render_template'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/notifications.rb:52:in `block in instrument'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/notifications.rb:52:in `instrument'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_view/render/rendering.rb:56:in `_render_template'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_view/render/rendering.rb:26:in `render'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_dispatch/middleware/show_exceptions.rb:88:in `rescue_action_locally'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_dispatch/middleware/show_exceptions.rb:68:in `render_exception'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_dispatch/middleware/show_exceptions.rb:59:in `call'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/rack/logger.rb:13:in `call'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.2/lib/rack/runtime.rb:17:in `call'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.2/lib/rack/lock.rb:11:in `block in call'
  <internal:prelude>:10:in `synchronize'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.2/lib/rack/lock.rb:11:in `call'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_dispatch/middleware/static.rb:30:in `call'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:168:in `call'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:77:in `method_missing'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/rack/log_tailer.rb:14:in `call'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.2/lib/rack/content_length.rb:13:in `call'
  c:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.2/lib/rack/handler/webrick.rb:52:in `service'
  c:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  c:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  c:/Ruby192/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

Started POST "/mugshots" for 127.0.0.1 at 2011-03-16 23:12:29 -0700

TypeError (can't convert nil into Integer):

Was it helpful?

Solution

That tutorial is very old and probably not relevant for Rails 3.x. I'm not even sure attachment_fu works with the current version of Rails.

I recommend paperclip or carrierwave

You can see other options here

OTHER TIPS

There are some changes with attachment_fu but it's available in rails3.Still if you want can go for paperclip. attachment_fu

I have also faced such problem. The problem is because of attachment_fu gem or plugin. Just uninstall it and use any other plugin or gem will solve your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top