我很困惑要解决一个问题。我有一个POST表单
<input multiple="multiple" name="dog[gallery_pictures_attributes][][file]" type="file">
<input name="dog[gallery_pictures_attributes][][crop]">
<input name="dog[gallery_pictures_attributes][][resize]">
<input name="dog[gallery_pictures_attributes][][crop]">
<input name="dog[gallery_pictures_attributes][][resize]">
<input name="dog[gallery_pictures_attributes][][crop]">
<input name="dog[gallery_pictures_attributes][][resize]">
我需要接收一个参数数组,比如
"gallery_pictures_attributes"=>[
{"file"=>"ryJfcmF", "crop"=>"1638x1053+205+156", "resize"=>"1400x900"},
{"file"=>"ddfvdfv", "crop"=>"1638x1053+205+156", "resize"=>"1400x900"},
{"file"=>"eyfvfmF", "crop"=>"1638x1053+205+157", "resize"=>"1400x900"},
]}
但是我有
"gallery_pictures_attributes"=>[
{"file"=>"ryJfcmF"},
{"file"=>"ddfvdfv"},
{"file"=>"eyfvfmF", "crop"=>"1638x1053+205+157", "resize"=>"1400x900"},
{"crop"=>"1638x1053+205+156", "resize"=>"1400x900"},
{"crop"=>"1638x1053+205+156", "resize"=>"1400x900"}
]}
请通知
明白了!参数的顺序很重要!问题只在一个[文件]输入中,这就是为什么输入中的最后一个文件有[crop]和[resize]参数。解决了为[crop]和[resize]参数生成文件输入的问题:
<input type="file" name="dog[gallery_pictures_attributes][][file]">.
<input name="dog[gallery_pictures_attributes][][crop]">
<input name="dog[gallery_pictures_attributes][][resize]">
<input type="file" name="dog[gallery_pictures_attributes][][file]">
<input name="dog[gallery_pictures_attributes][][crop]">
<input name="dog[gallery_pictures_attributes][][resize]">
<input type="file" name="dog[gallery_pictures_attributes][][file]">
<input name="dog[gallery_pictures_attributes][][crop]">
<input name="dog[gallery_pictures_attributes][][resize]">