-
-
Save clayallsopp/3278719 to your computer and use it in GitHub Desktop.
having trouble with bubblewrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
People.get_people do |data| | |
@data = data | |
end | |
def self.get_people(&block) | |
BW::HTTP...do |response| | |
@people = BW::JSON... | |
block.call(@people) | |
end | |
end | |
#got this working as a find method: | |
def self.find(id, &block) | |
BubbleWrap::HTTP.get("http://myapp.com/api/#{id}.json") do |response| | |
@person = BW::JSON.parse(response.body) | |
block.call(@person) | |
end | |
end | |
#called like | |
def selected_person(id) | |
Person.find(id) do |p| | |
@person = p | |
end | |
@person | |
end | |
#where @person is now available throughout the controller, although its still not really right as I need to specify the 0th #member of @person i.e. | |
def viewDidAppear(animated) | |
self.title = @person[0]['first_name'] + " " + @person[0]['last_name'] | |
@label = UILabel.alloc.initWithFrame(CGRectZero) | |
@label.text = "Email: " + @person[0]['email'] | |
@label.sizeToFit | |
@label.center = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height / 2) | |
self.view.addSubview @label | |
end | |
#But I just can't seem to get the "index" call to work properly. | |
#I'm getting `undefined method `count' for #<BubbleWrap::HTTP::Query:0x6c08560 ...> (NoMethodError)` errors, the count coming in #the numberOfRowsInSection call. | |
def self.get_people(&block) | |
BubbleWrap::HTTP.get("http://vaynernet.com/api.json") do |response| | |
@ppl = BW::JSON.parse(response.body.to_str) | |
block.call(@ppl) | |
end | |
end | |
def viewDidLoad | |
super | |
self.title = "Directory" | |
Person.get_people do |people| | |
@data = people | |
end | |
... | |
end | |
Should I not be calling the Person.get_people class method in viewDidLoad? Or does this sound like the json im returning from my rails server is the issue? It's increasingly perplexing because the Person.find method is working well enough. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment