0

我想打印所有问题和状态字段。如何在数组中提取所需的数据?

这是我的数组:@category_questions

[#<Question id: 38, user_id: 1, question: "hi", question_status: 1, created_at: "2013-06-04 18:32:28", updated_at: "2013-06-04 18:32:28">, #<Question id: 40, user_id: 1, question: "urll", question_status: 1, created_at: "2013-06-04 18:34:57", updated_at: "2013-06-04 18:34:57">, #<Question id: 41, user_id: 1, question: "urll", question_status: 1, created_at: "2013-06-04 18:35:31", updated_at: "2013-06-04 18:35:31">]

我试过@category_questions[iteration_number][:some field]了,但没有用。

4

1 回答 1

2

要获取哈希数组:

@category_questions.map do |question| 
  {question: question.question, status: question.question_status} 
end

要获取数组数组:

@category_questions.map {|question| [question.question, question.question_status] }
于 2013-06-05T12:31:28.063 回答