我想打印所有问题和状态字段。 如何在数组中提取所需数据?
这是我的数组:@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]
,但它没有用。
答案 0 :(得分:2)
获取哈希数组:
@category_questions.map do |question|
{question: question.question, status: question.question_status}
end
获取数组数组:
@category_questions.map {|question| [question.question, question.question_status] }