我有一个查找操作的ActiveRecord结果:
tasks_records = TaskStoreStatus.find(
:all,
:select => "task_id, store_name, store_region",
:conditions => ["task_status = ? and store_id = ?", "f", store_id]
)
现在,我想将结果转换为如下所示的哈希数组:
[0] -> { :task_d => 10, :store_name=> "Koramanagala", :store_region=> "India" }
[1] -> { :task_d => 10, :store_name=> "Koramanagala", :store_region=> "India" }
[2] -> { :task_d => 10, :store_name=> "Koramanagala", :store_region=> "India" }
这样我就可以遍历数组,并向哈希添加更多元素,然后将结果转换JSON
为API响应。我怎样才能做到这一点?
另请参阅stackoverflow.com/q/20794398/165673
—
Yarin