我通过JS将图像存储在localStorage中。在用户执行操作后,我将localStorage放在json字符串中,并通过AJAX Post将其上传到Amazon S3:
var json = {"labelupload":{"label":localStorage['<%= li['_id'] %>'],"label_file_name":'<%= li['_id'] %>.jpg', "li_id":'<%= li['_id'] %>'}}
$.ajax({
type:'POST',
url:'/label-upload',
data: json
})
这很好用。图像被处理并进入控制器。但是,我总是在日志中收到500条消息:
Unpermitted parameter: li_id
Completed 500 Internal Server Error in 1005ms (ActiveRecord: 1.2ms)
Paperclip::AdapterRegistry::NoHandlerError (No handler found for "undefined"):
app/controllers/carts_controller.rb:109:in `label_upload'
“undefined”似乎是“label”参数,这是我的localStorage:
Parameters: {"labelupload"=>{"label"=>"undefined", "label_file_name"=>"558194ab64356300172a0000.jpg", "li_id"=>"558194ab64356300172a0000"}}
我不知道该怎么做。为什么localStorage在这里被认为是“未定义的”?如何摆脱此错误消息?