我按照一个简单的示例来上传文件(请参阅下面的代码链接)。当我向上传表单添加字段 <%= f.file_field :uploaded_data %>,并单击表单上的提交按钮(有或没有文件附件)时,我在网页中收到一条错误消息: 500 内部服务器错误
在服务器日志上我收到一条错误消息:TypeError(无法将 nil 转换为整数):
我在 Rails 3.0.5、Ruby 1.9.2、Windows 7 上
我使用的示例代码位于:http://clarkware.com/blog/2007/02/24/file-upload-fu
您将在下面找到服务器日志的打印件:
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'
在 2011-03-16 23:12:29 -0700 开始为 127.0.0.1 发布“/mugshots”
TypeError(无法将 nil 转换为 Integer):
最佳答案
该教程非常古老,可能与 Rails 3.x 无关。我什至不确定 attachment_fu 是否适用于当前版本的 Rails。
我推荐paperclip或 carrierwave
可以看到其他选项here
关于ruby-on-rails - ruby rails : Server error with while trying to upload a file using attachment_fu: (can't convert nil into Integer),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5335557/