Ruby Hash:无法将String转换为Integer TypeError
发布时间:2020-12-17 01:31:42 所属栏目:百科 来源:网络整理
导读:目前获取 Ruby Hash:无法将String转换为Integer错误.代码在edit_id行上失败. 我已经尝试过许多不同的解决方案,这些解决方案来自SE上已发布的类似问题,但不幸的是,它们都没有奏效 哈希: {"downloadID"=115,"PageID"=nil,"title"="hi","dlLink"="http://www.
目前获取
Ruby Hash:无法将String转换为Integer错误.代码在edit_id行上失败.
我已经尝试过许多不同的解决方案,这些解决方案来自SE上已发布的类似问题,但不幸的是,它们都没有奏效 哈希: {"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} 码: #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)为您提供了一个哈希数组.所以修复是edit_id = data [0] [“downloadID”].写p数据而不是put数据,你会看到数据是一个hash数组.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |