我有一个令人困惑的错误:
我使用Paperclip 2.3.5在Ruby 1.9.2上运行Rails 3.0.0。
当我上传文件时,我收到500错误。
NameError (uninitialized constant ActionDispatch::Request::UploadedFile):
config/initializers/fix_params.rb:13:in `normalize_parameters'
config/initializers/fix_params.rb:19:in `block in normalize_parameters'
config/initializers/fix_params.rb:19:in `each'
config/initializers/fix_params.rb:19:in `normalize_parameters'
config/initializers/fix_params.rb:19:in `block in normalize_parameters'
config/initializers/fix_params.rb:19:in `each'
config/initializers/fix_params.rb:19:in `normalize_parameters'
Rendered /Users/vjmayr/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (10.2ms)
我已经看到类似的事情发生在Rails 3.0.2和.3但我不知道为什么会发生在这里。谁能帮助我找到问题?
谢谢!的Valentin
ADDED config / initializers / fix_params.rb:
module ActionController
class Request
private
# Convert nested Hashs to HashWithIndifferentAccess and replace
# file upload hashs with UploadedFile objects
def normalize_parameters(value)
case value
when Hash
if value.has_key?(:tempfile)
upload = value[:tempfile]
upload.extend(UploadedFile)
upload.original_path = value[:filename]
upload.content_type = value[:type]
upload
else
h = {}
value.each { |k, v| h[k] = normalize_parameters(v) }
h.with_indifferent_access
end
when Array
value.map { |e| normalize_parameters(e) }
else
value.force_encoding(Encoding::UTF_8) if value.respond_to?(:force_encoding)
value
end
end
end
end
答案 0 :(得分:0)
所以这是修改后的fix_params.rb片段
...
if value.has_key?(:to_tempfile)
upload = value[:to_tempfile]
...
干杯,
缬氨酸