Currently getting a Ruby Hash: can't convert String into Integer
error. The code fails on the edit_id line.
I've tried many different solutions from similar questions already posted on SE, but unfortunately none of them have worked.
Hash:
{"downloadID"=>115, "PageID"=>nil, "title"=>"hi", "dlLink"=>"http://www.a.com", "imgSrc"=>"http://www.a.com", "caption"=>"aaaa", "dlLive"=>nil, "createdAt"=>nil, "user_id"=>7}
Code:
#edit download
put '/view1/downloadedit' do
data = JSON.parse(request.body.read)
puts data
edit_id = data["downloadID"]
puts edit_id
@download = Download.get(:download_id => edit_id)
puts data
if @download.update(data)
status 201
puts 'edit saved okay'
else
status 201
puts 'edit failed to SAVE'
end
end
JSON.parse(request.body.read)
gives you an array of hash. So the fix isedit_id = data[0]["downloadID"]
. Writep data
instead ofputs data
, you will see thedata
is an array of hash.