Zack Nathan wrote:
> 
> Of course I did just that! But i still got the error..

Well then you are assuming that the wrong thing is nil...  perhaps it 
isn't @parsed_response that is nil.  Try working through the issue with 
irb and seeing what your results are and work through how you'd navigate 
the results.

All I can say is that it works just fine (accessing the calorieking api 
and displaying the results), having never looked at their API or used 
HTTParty before this a.m.

Model:

class Foodq < Object
  include HTTParty
  basic_auth "84294d7ae4454189bf2a3ebc37a0e421", ""

  def trial_search
    
self.class.get("http://foodsearch1.webservices.calorieking.com/rest/search/chicken";)
  end
end

Controller:

class FoodqsController < ApplicationController
  def foods
    @foodq = Foodq.new
    @response = @foodq.trial_search
  end
end

View (foods.html.haml - yeah, I use haml, but it's pretty easy to read, 
and sooooo much nicer to code):

%table{:border => "1", :cellspacing => "1", :cellpadding => "1"}
  - @response['searchresults']['category'].each do |cat|
    %tr
      %td{:colspan => "2"}= h(cat['name'])
    - cat['foods']['food'].each do |fd|
      %tr
        %td= h(fd['id'])
        %td= h(fd['display'])

Easy peasy...
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to