访问哈希Ruby中的非哈希值 - Ruby on Rails

时间:2014-03-06 19:28:40

标签: ruby-on-rails ruby file file-upload hash

我有以下内容:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"b3+vGGBgjaxZ5W7UhJIZfqK9vz7MsAi1ipeDrDV1vgo=", "commit"=>"Upload", "remotipart_submitted"=>"true", "X-Requested-With"=>"IFrame", "X-Http-Accept"=>"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01", "uploaded_file"=>{"uploaded_file"=>#<ActionDispatch::Http::UploadedFile:0xb5f72ac8 @tempfile=#<Tempfile:/tmp/RackMultipart20140306-2294-1ifwfm5>, @original_filename="INSTRUCTION.txt", @content_type="text/plain", @headers="Content-Disposition: form-data; name=\"uploaded_file[uploaded_file]\"; filename=\"INSTRUCTION.txt\"\r\nContent-Type: text/plain\r\n">}}

所以这里如果我想访问参数“uploaded_file”,我会去:

params[:uploaded_file]

如果我想在里面获取uploaded_file值,我会这样做:

(params[:uploaded_file])["uploaded_file"]

将返回:

<ActionDispatch::Http::UploadedFile:0xb5f72ac8

但我想知道,我应该如何访问此uploaded_file哈希中的@headers?

谢谢你的建议! (:

PS:如果有人知道什么

<ActionDispatch::Http::UploadedFile:0xb5f72ac8

意味着如果它对某些东西有用它会很棒。 {:

1 个答案:

答案 0 :(得分:1)

ActionDispatch::Http::UploadedFile:0xb5f72ac8指的是ActionDispatch::Http::UploadedFile class

的实例

要访问@headers,请使用

params[:uploaded_file][:uploaded_file].headers