2010-05-18 42 views
0

我有一个从一个窗体发送的两个数据数组,一个叫做transloaded,另一个视频是模型的实际形式。我需要得到[:video_encoded] [:url]并将其保存到[:video] [:flash_url]合并传递的参数

这是传递参数或转载,当我尝试访问[:transload] [:results] [ :video_encode]我得到零。

print params[:transload] 
    { 
    "assembly_id":"d59b4293b3d79d2ccd1948c02421c6a6", 
    "status":"success", 
    "uploads":{ 
     "video":{ 
      "name":"bbc_one.mp4", 
      "mime":"video/mp4", 
      "ext":"mp4", 
      "size":601104, 
      "meta":{ 
       "width":720, 
       "height":404, 
       "video_fps":25, 
       "video_bitrate":null, 
       "video_format":"avc1", 
       "video_codec":"ffh264", 
       "audio_bitrate":"128k", 
       "audio_codec":"faad", 
       "duration":3.07, 
       "device_vendor":null, 
       "device_name":null, 
       "device_software":null, 
       "latitude":null, 
       "longitude":null 
      }, 
      "url":"http://tmp.transloadit.com/" 
     } 
    }, 
    "results":{ 
     "video_encode":{ 
      "name":"bbc_one.flv", 
      "mime":"video/x-flv", 
      "steps":["encode","export"], 
      "ext":"flv", 
      "size":388317, 
      "meta":{ 
       "width":480, 
       "height":320, 
       "video_fps":25, 
       "video_bitrate":"512k", 
       "video_format":"FLV1", 
       "video_codec":"ffflv", 
       "audio_bitrate":"64k", 
       "audio_codec":"mp3", 
       "duration":3.11, 
       "device_vendor":null, 
       "device_name":null, 
       "device_software":null, 
       "latitude":null, 
       "longitude":null 
      }, 
      "url":"http://s3.transloadit.com/b7deac9c96af6c745e914e25d0350baa/7a/2b09e822265ac2328789b40dcc02ae/bbc_one.flv" 
     }, 
     "video_encode_iphone":{ 
      "name":"bbc_one.qt", 
      "mime":"video/quicktime", 
      "steps":["encode_iphone","export"], 
      "ext":"qt", 
      "size":218236, 
      "meta":{ 
       "width":480, 
       "height":320, 
       "video_fps":25, 
       "video_bitrate":null, 
       "video_format":"avc1", 
       "video_codec":"ffh264", 
       "audio_bitrate":"128k", 
       "audio_codec":"faad", 
       "duration":3.04, 
       "device_vendor":null, 
       "device_name":null, 
       "device_software":null, 
       "latitude":null, 
       "longitude":null 
      }, 
      "url":"http://s3.transloadit.com/31/58bcc80d5345e52a42c9773125e8f0/bbc_one.qt" 
     } 
    } 
} 

这是我想使用

video_links = { 
    :flash_url => params[:transload][:results][:video_encode][:url], 
    :mp4_url => params[:transload][:results][:video_encode_iphone][:url] 
} 
params[:video].merge(video_links) 

回答

1

的问题很简单::results != "results"或者换句话说:你的哈希有String类型的密钥,但你与类型Symbol访问它们。

+0

我认为这是因为结果是json,我不知道。 params [:transload] = ActiveSupport :: JSON.decode(params [:transload]) 解决了它 – 2010-05-18 02:50:47

+0

您应该接受帮助您的答案。 – nathanvda 2010-05-18 08:06:01

+0

谢谢nathanvda,即时通讯新的到stackoverflow :) – 2010-05-20 00:51:03