나는 해시는 다음과 같습니다 내 레일 응용 프로그램에 게시되고 있습니다HashWithIndifferentAccess를 String으로 변환 할 수 없습니까?
{"signed_request"=>"...",
"buyer"=>"1064897036",
"receiver"=>"1064897036",
"order_id"=>"224539980951036",
"method"=>"payments_get_items",
"test_mode"=>"1",
"order_info"=>{"description"=>"None",
"image_url"=>"",
"price"=>"1",
"product_url"=>"",
"title"=>"Premium Membership"}}
내가이 문제를 분석하고 다시 적절한 응답을 게시 할 수있는 몇 가지 코드를 차용하고있다. 먼저 서명 된 요청을 구문 분석하여 제대로 작동하는지 확인한 다음 주문 정보를 작성하여 서버로 다시 보냅니다. 문제가 시작된다 그건 것 같습니다 :
...
elsif method == 'payments_get_items'
order_info = params[:order_info]
item = JSON.parse(order_info)
item['price'] = item['price'].to_i
# for url fields, if not prefixed by http://, prefix them
url_key = [ 'product_url', 'image_url' ]
url_key.each do |key|
if item[key][0..6] != 'http://'
item[key] = "http://#{item[key]}"
end
end
# if payload['test_mode']
if request.params['test_mode']
update_keys = ['title', 'description']
update_keys.each do |key|
item[key] = '[Test Mode] ' + item[key]
end
end
data['content'] = [item]
end
data['method'] = method
render :json => data
end
나는이 오류 받고 있어요 :
can't convert ActiveSupport::HashWithIndifferentAccess into String
그것은이 라인에 의해 발생되는 것 :
item = JSON.parse(order_info)
잘 모르겠어요를 그것이 무엇을 의미하는지. 대안으로, 나는 서버가 아이템 번호를 건네 줄 수 있다는 것을 알았고, 데이터베이스를 질의하고 정보를 JSON으로 푸시 (해시를 분석하는 대신) 할 수 있지만, 내가 할 수 있다면이 일을 할 수 있습니다. 이견있는 사람?