Hi i've been struggling for a while now trying to grasp how to use the data received in an api call. A lot of tutorials are either outdated or focus solely on creating API's rather than using them. I understand the concepts behind hashes and arrays but im really having a problem looping through a hash eg
"section_title"=>"Walmart.com: Free 2-Day Shipping on Millions of Items",
"computers & technology",
I've finally mastered creating the API logic then calling this logic in the controller and finally displaying to html but all i am able to figure out is @(NAMEOFFUNC)['(each API Returns a unique attribute)'] or @output['products'] will print out the entire value of the "products" key. (Should mention i dont know why it returns a hashed array and not a simple array or objects. i think its because of ruby being used in the back end so if a JSON data structure is called it auto returns a ruby hash, i know in the call logic i set the format to :JSON could have been xml) Then im able to individually use something like this @output['products']['name'] or @(NAMEOFFUNCTION)['UNIQUATR'][(id. of the product)]['(NAMEOFKEY)'] and sure enough this takes the key Name and prints its value. Images however dont work. <%= image_tag (@output['products']['images']) %> returns nill this i know is because of the layout of the hashed array. ruby thinks the actual link of the image is a key that should have a value but its actually a value or object.
************ How could i get the image to display properly. ?
************ Also how could i loop through all the products displaying there value?
The looping part i understand that the loop only needs to have this contained inside it. and should have a erb to start and erb to end
<% @output.each do |out| %>
<!--Start a loop here-->
<div class="tile scale-anm arduinoBD">
<%= image_tag out['images'], size: '150'%>
<div class="content-details fadeIn-left">
<h3> <%= out['name'] %> </h3>
<p> <%= out['description'] %></p>
<p> <%= out['price']%> </p>
<!--finish the loop here-->
<% end %>