获得ActiveRecord object对象的属性类型

获得单个属性类型的方法:

(1)User.columns_hash["name"].type
(2)User.type_for_attribute('name').type

如果想获得model的所有属性类型列表,可以如下:

(1)User.columns_hash.map {|k,v| v.type} 
(2)User.columns.map(&:type) #gets them all
(3)User.columns.map(&:type).uniq #gets the unique ones

你可能感兴趣的:(获得ActiveRecord object对象的属性类型)