Remote JSON Source – Ruby on Rails

Hey everyone,

Just a quick post on how to retrieve a remote JSON source so I don’t forget.

  1. require 'open-uri'
  2. require 'json'
  3.  
  4. #Retrieve source (controller/model)
  5. @results = JSON.parse(open("http://www.myjsonsource.com/jsonfeed_num1").read)
  6.  
  7.  
  8. #In view
  9. <% @results.each do |result| %>
  10.    <%= result['value'] %>
  11. <% end %>

That’s all there is to it, let me know if you have any problems!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.