Consume an API

0

I have this API code that I'm doing to the consumer, it shows me an error that says:

"no implicit conversion of String into Integer"

I do not know if I need to add anything to the codes.

Image of the codes I'm using I do not know if I need something

    
asked by Oscar Diaz 02.09.2017 в 21:52
source

2 answers

0

Some (or all) of @articles is an array, so the [] method applied in article expects a number, however you are passing a text string:

<%= article["image_url"] %>

To fix it, you must verify the structure that is returning the API (i.e. print the @articles content) so that you can give the appropriate treatment to each element.

Generally, with HTTParty.get (considering the current response of your API), you would do something like this:

@articles = HTTParty.get(...).body[:articles]

<% @articles.each do |article| %>
  <%= article["image_url"] %>
<% end %>
    
answered by 03.09.2017 / 03:43
source
0

You are treating a string as a number.

This can usually happen when you want to do a mathematical operation with a string

ex:

 "no soy un número" + 4 

Notice if you do not have strings fields in the params that you think are numbers

    
answered by 03.09.2017 в 00:11