Use JSON object returned from url in rails

I am extracting some data from the site using its API key and some other parameters. I get the data as a JSON object. Now my question is how to use this JSON object in my rails application, perhaps something like using an instance variable that stores the JSON object, and then creates its erb template, which wold displays an array of instance variables. I tried to use some of the solutions in Stack Overflow, but did not understand them correctly, some more basic recommendations will be useful.

+5
source share
1 answer

Ruby on Rails JSON support is provided using ActiveSupport :: JSON, but it spins the JSON stone behind the scene. Therefore, you can choose your choice.

Check out this example,

@data = [{"id":"7354857336","owner":"49091484@N07","secret":"dc7ce98bf9","server":"8151","farm":9,"title":"01_resize","ispublic":1,"isfriend":0,"isfamily":0},
{"id":"7355453164","owner":"41440187@N07","secret":"b0bc716ee6","server":"7225","farm":8,"title":"{Laduree Macaroons} explore #2","ispublic":1,"isfriend":0,"isfamily":0},
{"id":"7355183126","owner":"38937613@N03","secret":"c342e37a57","server":"7232","farm":8,"title":"REFLECTED AT MIDNIGHT [EXPLORED]","ispublic":1,"isfriend":0,"isfamily":0}]

In the .erb file

<% @data.each  do |photo| %>
 <%= photo.id%> ---<%= photo.title %><br></br>
<% end %>
+2
source

All Articles