合并传递的参数

时间:2010-05-18 02:12:03

标签: ruby-on-rails

我有一个从表单发送的两个数据数组,一个名为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 个答案:

答案 0 :(得分:1)

问题很简单::results != "results"或换句话说:您的哈希键具有String类型的键,但您使用Symbol类型访问它们。