Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.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
Ruby on rails 如何在RubyonRails中使用另一个数组中的元素为数组中的每个元素设置值_Ruby On Rails_Ruby_Arrays - Fatal编程技术网

Ruby on rails 如何在RubyonRails中使用另一个数组中的元素为数组中的每个元素设置值

Ruby on rails 如何在RubyonRails中使用另一个数组中的元素为数组中的每个元素设置值,ruby-on-rails,ruby,arrays,Ruby On Rails,Ruby,Arrays,我可以使用ruby on rails中另一个数组中的元素为数组中的每个元素设置值吗??: 以下是我的例子: ids = [1234,5678,....] @fb = [](array) @fb[0] = @graph.get_connections("#{ids[0](1234)}","?fields=posts) @fb[1] = @graph.get_connections("#{ids[1](5678)}","?fields=posts) 我能在RubyonRails中做到这一点吗?我该

我可以使用ruby on rails中另一个数组中的元素为数组中的每个元素设置值吗??: 以下是我的例子:

ids = [1234,5678,....]
@fb = [](array)
@fb[0] = @graph.get_connections("#{ids[0](1234)}","?fields=posts)
@fb[1] = @graph.get_connections("#{ids[1](5678)}","?fields=posts)
我能在RubyonRails中做到这一点吗?我该怎么做??请帮帮我

我尝试这样做:

ids = [1234,5678,....]
ids.each do |id|
@fb = @graph.get_connections("#{id}","?fields=posts)

我想我的@fb将获得两个id为1234和5678的值,但它只获得一个id为1234的值,所以我想为每个id为1234和5678的@fb设置值。

也许是这样的?让我们从ids数组的大小减去1开始倒计时到零。在某种程度上,您确实应该保证数组的大小相同(或者@fb更大)

查看

ids = [ 123, 456 ]
connections = ids.map do |id|
  @graph.get_connections("#{ id }","?fields=posts")
end

请正确粘贴语法代码,并给出更多解释。在你的问题中有太多的猜测空间:)你知道,我不知何故假设他已经有了一个数组@fb,他正在其中添加或替换值。地图绝对是一条路要走。
ids = [ 123, 456 ]
connections = ids.map do |id|
  @graph.get_connections("#{ id }","?fields=posts")
end