Note that there are some explanatory texts on larger screens.

plurals
  1. POBubblewrap HTTP -> Table View; method returns bubblewrap query instead of response data
    text
    copied!<p>I'm trying out Rubymotion and can't seem to do figure how to accomplish what seems like a simple task.</p> <p>I've set up a UITableView for a directory of people. I've created a rails back end that returns json.</p> <p>Person model has a get_people class method defined:</p> <pre><code>def self.get_people BubbleWrap::HTTP.get("http://myapp.com/api.json") do |response| @people = BW::JSON.parse(response.body.to_str) # p @people prints [{"id"=&gt;10, "name"=&gt;"Sam"}, {etc}] to the console end end </code></pre> <p>In the directory_controller I just want to set an instance variable for @data to the array that my endpoint returns such that I can populate the table view.</p> <p>I am trying to do <code>@data = Person.get_people</code> in viewDidLoad, but am getting an error message that indicates the BW response object is being passed instead: <code>undefined method</code>count' for #BubbleWrap::HTTP::Query:0x8d04650 ...> (NoMethodError)` </p> <p>So if I hard code my array into the get_people method after the BW response block everything works fine. But I find that I am also unable to persist an instance variable through the close of the BW respond block.</p> <pre><code>def self.get_people BubbleWrap::HTTP.get("http://myapp.com/api.json") do |response| @people = BW::JSON.parse(response.body.to_str) end p @people #prints nil to the console # hard coding [{"id"=&gt;10, "name"=&gt;"Sam"}, {etc}] here puts my data in the table view correctly end </code></pre> <p>What am I missing here? How do I get this data out of bubblewrap's response object and in to a usable form to pass to my controllers?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload