0

I'm trying to implement Bitcoin payments using Block.io, and when I request a balance from the bitcoin address, it responds with a hash. How can I extract specific information and make the data user friendly.

The hash I need to extract the information from looks like this:

{"status"=>"success", "data"=>{"network"=>"BTCTEST", "available_balance"=>"0.01000000", "pending_received_balance"=>"0.00000000"}} 

I have a controller with method:

class PaymentsController < ApplicationController
   def index
     @balance = BlockIo.get_balance
   end
end

And in the view I have:

<%= @balance.each do |bal| %>
   <p>Balance: <%= bal[1]["available_balance"] %></p>
<% end %>   

And the result that I get in the index.html.erb view is like this:

Balance:

Balance: 0.01000000

{"status"=>"success", "data"=>{"network"=>"BTCTEST", "available_balance"=>"0.01000000", "pending_received_balance"=>"0.00000000"}} 

As you can see above, it shows Balance twice and also still shows the hash in the view.

How can I only show Balance: 0.01000000? Any assistance or comment is greatly appreciated.

1 Answer 1

1

First, this is Hash, not Array:

{"status"=>"success", "data"=>{"network"=>"BTCTEST",  "available_balance"=>"0.01000000", "pending_received_balance"=>"0.00000000"}} 

Second, you can do this in your view file:

<p>Balance: <%= @balance["data"]["available_balance"] %></p>
Sign up to request clarification or add additional context in comments.

1 Comment

@MorezSA You can do this: In your routes.rb get 'payment/result=:balance' => 'payment#show', as: :test_payment In your controller: def show end In your view: test_payment_path(@balance["data"]["available_balance"])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.