Sunday, 15 August 2010

ruby on rails - How to present json values with html erb template as an array -



ruby on rails - How to present json values with html erb template as an array -

i making simple request httparty , want display them list code below.

def index reqd = httparty.get("https://api.dynadot.com/api3.xml?key=xxxxxx&command=search&domain0=mydomain.com&domain1=mydomain.net").body @results = hash.from_xml(reqd) end

output is

{"results"=>{"searchresponse"=>[{"searchheader"=>{"successcode"=>"0", "domainname"=>"mydomain.com", "status"=>"success"}}, {"searchheader"=>{"successcode"=>"0", "domainname"=>"mydomain.net", "status"=>"success", "available"=>"no"}}]}}

how utilize such can have result in index.html.erb this

<% @results.each |result| %> ##can phone call value here domain name, status etc <% end %>

i'm not sure want, perhaps help:

@results = {"results"=>{"searchresponse"=>[{"searchheader"=>{"successcode"=>"0", "domainname"=>"mydomain.com", "status"=>"success"}}, {"searchheader"=>{"successcode"=>"0", "domainname"=>"mydomain.net", "status"=>"success", "available"=>"no"}}]}} @results["results"]["searchresponse"].map { |x| x["searchheader"] }.each |s| puts s["successcode"] puts s["domainname"] puts s["status"] end

result:

mydomain.com success mydomain.net success

ruby-on-rails json ruby-on-rails-3 ruby-on-rails-4

No comments:

Post a Comment