railsを使いstripeの残高を表示したいのですがundefinedと表示されてしまいます。
何かわかる方は回答お願いします。
log
1Started GET "/posts/mydata" for ::1 at 2020-10-04 15:42:26 +0900 2Processing by PostsController#mydata as */* 3 User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 8], ["LIMIT", 1]] 4 ↳ app/controllers/posts_controller.rb:108:in `set_notifications' 5 Notification Load (0.2ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."visited_id" = $1 AND "notifications"."checked" = $2 ORDER BY "notifications"."created_at" DESC LIMIT $3 [["visited_id", 8], ["checked", false], ["LIMIT", 10]] 6 ↳ app/controllers/posts_controller.rb:110:in `set_notifications' 7 Rendering posts/mydata.js.erb 8 Rendered posts/mydata.js.erb (Duration: 3.5ms | Allocations: 158) 9Completed 200 OK in 567ms (Views: 22.9ms | ActiveRecord: 0.5ms | Allocations: 6100)
データ構造はこんな感じです。
{ "object": "balance", "available": [ { "amount": 27056, "currency": "jpy", "source_types": { "card": 27056 } } ], "connect_reserved": [ { "amount": 0, "currency": "jpy" } ], "livemode": false, "pending": [ { "amount": -21394, "currency": "jpy", "source_types": { "card": -21394 } } ] }
jserb
1var data = <%== @balance %>; 2var result = '<div>' 3 result += data.pending.amount 4result += '</div>' 5$('#result').html(result);
data.pending.amountをdata.objectにしたら正しく表示されるので@balanceはあっていると思います。
htmlslim
1div#result 2 |no information... 3javascript: 4var f = function(){ 5 $.ajax({ 6 type: 'GET', 7 url: '/posts/mydata' 8 }); 9}; 10f();
rails6
ruby2.7
回答1件
あなたの回答
tips
プレビュー