Reputation: 343
I have this hash, it's a result of query to my management system.
a = {
"total" => 3310,
"subtotal" => 2,
"page" => 1,
"per_page" => 20,
"search" => "fact = ipaddress and host ~ test.com",
"sort" => { "by" => nil, "order" => nil },
"results" => {
"host1.test.com" => { "ipaddress" => "192.168.253.240" },
"host2.test.com" => { "ipaddress" => "192.168.253.253" }
}
}
And I want to store this pool of IP adresses of my hosts in new array and show the new arrays's values with template erb file. Somethig like this:
host1.test.com 192.168.253.240
host2.test.com 192.168.253.253
The result of the request can be a different number of hosts with different name. This hash is an example.
Upvotes: 0
Views: 350
Reputation: 2345
You can assign it to a variable - @ip_addresses
@ip_addresses = a['results']
Then use it in the template file
<% @ip_addresses.each do |host, info| %>
<%= host %> - <%= info['ipaddress'] %>
...
<% end %>
Upvotes: 2