Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于Nano动态存储的Rubymotion查询_Ruby_Rubymotion - Fatal编程技术网

基于Nano动态存储的Rubymotion查询

基于Nano动态存储的Rubymotion查询,ruby,rubymotion,Ruby,Rubymotion,我在iOS应用程序中有一个方法,它查询数据库,然后将数据放入ruby循环中。我让循环动态地向ruby循环中添加一个数字,但它正在吸引所有用户 # Query all children in database child = Child.all # Loop through children and add count. count = child.count 0.upto(count - 1) do |c| p "#{@child.each do |child| child.first

我在iOS应用程序中有一个方法,它查询数据库,然后将数据放入ruby循环中。我让循环动态地向ruby循环中添加一个数字,但它正在吸引所有用户

# Query all children in database

child = Child.all

# Loop through children and add count.

count = child.count
0.upto(count - 1) do |c|
  p "#{@child.each do |child| child.first_name end}" + "['#{c}']"
end
通过这组查询和循环,我得到了以下答案:

“[子项:0x8dee0,子项:0x8de2860]['0']”, [子项:0x8dee0,子项:0x8de2860][1']

我不需要为每个数字提供相同的子项,而是需要它按如下方式查询答案:

“[子项:0x8dee0]['0']”, “[子项:0x8de2860]['1']”


任何帮助都将不胜感激。谢谢。

如果循环试图打印数组中子对象的名字, 试试这个:

0.upto(count - 1) do |c|
  p child[c].first_name
end
或者,您可以完全跳过计数:

child.each do |achild|
  p achild.first_name
end