Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails ActiveRecord使用适当的数据类型获取记录_Ruby On Rails_Ruby_Activerecord - Fatal编程技术网

Ruby on rails Rails ActiveRecord使用适当的数据类型获取记录

Ruby on rails Rails ActiveRecord使用适当的数据类型获取记录,ruby-on-rails,ruby,activerecord,Ruby On Rails,Ruby,Activerecord,我使用的是Ruby,我想要散列格式的数组中的数据 我已经试用了ActiveRecord的选择方法。但它以字符串格式返回所有数据,而不管其在数据库中的类型是什么。所有数字也以字符串格式返回。您可以使用: MyModel.all.map &:attributes 这相当于: MyModel.find(:all).collect {|x| x.attributes} 您可以使用: MyModel.all.map &:attributes 这相当于: MyModel.find(:a

我使用的是Ruby,我想要散列格式的数组中的数据

我已经试用了ActiveRecord的选择方法。但它以字符串格式返回所有数据,而不管其在数据库中的类型是什么。所有数字也以字符串格式返回。

您可以使用:

MyModel.all.map &:attributes
这相当于:

MyModel.find(:all).collect {|x| x.attributes}
您可以使用:

MyModel.all.map &:attributes
这相当于:

MyModel.find(:all).collect {|x| x.attributes}