我需要产生哈希的循环,而不是对象数组。我有这个:
json.service_issues @service.issues do |issue|
json.set! issue.id, issue.name
end
结果:
service_issues: [
{
3: "Not delivered"
},
{
6: "Broken item"
},
{
1: "Bad color"
},
{
41: "Delivery problem"
}
]
我需要这个:
service_issues: {
3: "Not delivered",
6: "Broken item",
1: "Bad color",
41: "Delivery problem"
}
是否可以在不手动将 AR 结果转换为哈希的情况下执行此操作?