1
我有一個令人困惑的錯誤:的Rails 3 - 回形針:未初始化不斷ActionDispatch ::支持:: UploadedFile的
我運行Rails 3.0.0關於Ruby 1.9.2與2.3.5回形針。
當我上傳一個文件時,我得到一個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,但我不知道爲什麼會發生在這裏。任何人都可以幫我找到問題嗎?
謝謝!瓦倫丁
添加的配置/初始化/ 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
你可能想看看'配置/初始化/ fix_params.rb '因爲這是Rails和它的某種非標準擴展可能會發生故障。也許你可以修改這個問題,並添加關於內容的細節。 – tadman 2010-11-18 18:59:13
嗨tadman,我添加了fix_params.rb到我的問題。我保持原來的安裝不變。 – 2010-11-18 19:16:10