我正在尝试学习运动资源https://github.com/tkadauke/motion-resource的例子。在使用此异步代码以正确格式获取数据时遇到困难:
def all_friends(&block)
Friends.find_all do |friends, response|
if response.ok?
puts friends.inspect
block.call friends
else
App.alert response.error_message
end
end
end在这个实现中,我有一个有很多朋友的用户资源。我试着用User.current.all_friends为这个用户找到所有的朋友
当数据返回时,当我试图迭代它时,我会收到一个错误,因为它返回为一个BubbleWrap HTTP查询。
#<BubbleWrap::HTTP::Query:0xc54c7a0 ...> 发布于 2014-02-17 21:31:14
这个堆栈溢出问题解决了在这个问题中遇到的相同问题:What is the iOS (or RubyMotion) idiom for waiting on a block that executes asynchronously?
发布于 2014-02-10 16:57:42
我想知道您的错误来自哪个行号。
“未定义方法` `each‘for #”
你试过移除这条线吗?
block.call friends? 您的示例似乎来自具有以下工作代码行的文档.
User.find_all do |users, response|
if response.ok?
puts users.inspect
else
App.alert response.error_message
end
end希望你能弄明白。如果代码是可执行的,就更容易排除故障。
https://stackoverflow.com/questions/21640187
复制相似问题