[英]Rails 3 - Paperclip: uninitialized constant ActionDispatch::Request::UploadedFile
I have a confusing error: 我有一个令人困惑的错误:
I run Rails 3.0.0 on Ruby 1.9.2 with Paperclip 2.3.5. 我在使用Paperclip 2.3.5的Ruby 1.9.2上运行Rails 3.0.0。
When I upload a file I get a 500 error. 上传文件时出现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)
I have seen similar things happen with Rails 3.0.2 and .3 but I have no idea why it happens here. 我已经看到过Rails 3.0.2和.3会发生类似的事情,但是我不知道为什么会在这里发生。 Con anyone help me with finding the problem?
骗子有人帮我找到问题吗?
Thanks! 谢谢! Valentin
瓦伦丁
ADDED config/initializers/fix_params.rb: 添加的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
tadman (Thanks!) pointed me towards the right solution: All I had to do was change the value from tempfile to to_tempfile. tadman(谢谢!)为我提供了正确的解决方案:我要做的就是将值从tempfile更改为to_tempfile。 This prabably won't happen to too many people, but I thought I'd mention as there has been a similar discussion around that due to a recent change in stable rails 3.0.3 by tenderlove, which is philisophically absolutely correct - but threw off some people...
这种情况大概不会发生在太多的人身上,但是我想提一提,因为围绕着类似的讨论,这是由于最近招标人对lovelove的稳定导轨3.0.3进行了更改,这在哲学上是绝对正确的-但被抛弃了有些人...
So here is the changed fragment of fix_params.rb 所以这是fix_params.rb的更改片段
...
if value.has_key?(:to_tempfile)
upload = value[:to_tempfile]
...
Cheers, 干杯,
Val 值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.