我有一个JSON字符串数组。如何将它们转换为Activerecord模型数组?我的当前代码看起来像这样,我不想一个一个地迭代它:
jsons = ['{"id": 1, "field1" : "value1"}'] #this is an array of jsons
models = [] #i want an array of models back
jsons.each do |json|
if(json == nil)
next
end
begin
hash = JSON.parse(json)
rescue
next
end
model = className.new
model.attributes = hash
model.id = hash["id"]
models << model
end