新手问题 对象转换成 hash

kloong777 · March 14, 2014 · Last by kloong777 replied at March 14, 2014 · 3853 hits

想把一条从数据库查询出来的记录对象转换成 hash

# 转换成

{ id=>2,name=>‘无敌’, types=> 2, action=>'5 秒无敌'}

card['id'] = card.id 只会用笨方法,给每个字段赋值,如果字段比较多的话会比较麻烦

谁有更好的办法吗

cart.attributes

嗯,谢谢,是这么回事

You need to Sign in before reply, if you don't have an account, please Sign up first.