当前位置:  开发笔记 > 后端 > 正文

如何按属性订购对象?

如何解决《如何按属性订购对象?》经验,为你挑选了0个好方法。

我现在面对这个问题一段时间了,请仔细研究一下.

object.inspect给了我这个输出


raise object.to_yaml给出了这个输出

-- !ruby/object:RawMaterial
raw_attributes:
  costing_id: 
  id: 
  name: Jam Button 9 mm Antique Silver
  rate: '1'
  raw_material_wastage: '0'
  total_raw_material: '8'
  slug: 
  created_at: 
  updated_at: 
  inventory_item_id: '758'
  costing_wastage: '0'
  pick_from_order_sheet: f
attributes: !ruby/object:ActiveRecord::AttributeSet
  attributes: !ruby/object:ActiveRecord::LazyAttributeHash
    types:
      id: &3 !ruby/object:ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer
        precision: 
        scale: 
        limit: 
        range: !ruby/range
          begin: -2147483648
          end: 2147483648
          excl: true
      name: &2 !ruby/object:ActiveRecord::Type::String
        precision: 
        scale: 
        limit: 255
      rate: &1 !ruby/object:ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Float
        precision: 
        scale: 
        limit: 
      raw_material_wastage: *1
      total_raw_material: *1
      slug: *2
      costing_id: *3
      created_at: !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter
        subtype: &4 !ruby/object:ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime
          precision: 
          scale: 
          limit: 
      updated_at: !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter
        subtype: *4
      inventory_item_id: *3
      costing_wastage: *1
      pick_from_order_sheet: &5 !ruby/object:ActiveRecord::Type::Boolean
        precision: 
        scale: 
        limit: 
    values:
      id: '70'
      name: Jam Button 9 mm Antique Silver
      rate: '1'
      raw_material_wastage: '0'
      total_raw_material: '8'
      slug: 
      costing_id: '34'
      created_at: '2015-06-10 09:12:13.721016'
      updated_at: '2015-06-10 09:12:14.075739'
      inventory_item_id: '758'
      costing_wastage: '0'
      pick_from_order_sheet: f
    additional_types: {}
    materialized: true
    delegate_hash:
      costing_id: !ruby/object:ActiveRecord::Attribute::FromUser
        name: costing_id
        value_before_type_cast: 
        type: *3
        value: 
      id: !ruby/object:ActiveRecord::Attribute::FromDatabase
        name: id
        value_before_type_cast: 
        type: *3
        value: 
      name: !ruby/object:ActiveRecord::Attribute::FromDatabase
        name: name
        value_before_type_cast: Jam Button 9 mm Antique Silver
        type: *2
        value: Jam Button 9 mm Antique Silver
      rate: !ruby/object:ActiveRecord::Attribute::FromDatabase
        name: rate
        value_before_type_cast: '1'
        type: *1
        value: 1.0
      raw_material_wastage: !ruby/object:ActiveRecord::Attribute::FromDatabase
        name: raw_material_wastage
        value_before_type_cast: '0'
        type: *1
        value: 0.0
      total_raw_material: !ruby/object:ActiveRecord::Attribute::FromDatabase
        name: total_raw_material
        value_before_type_cast: '8'
        type: *1
        value: 8.0
      slug: !ruby/object:ActiveRecord::Attribute::FromDatabase
        name: slug
        value_before_type_cast: 
        type: *2
        value: 
      created_at: !ruby/object:ActiveRecord::Attribute::FromUser
        name: created_at
        value_before_type_cast: 
        type: !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter
          subtype: *4
        value: 
      updated_at: !ruby/object:ActiveRecord::Attribute::FromUser
        name: updated_at
        value_before_type_cast: 
        type: !ruby/object:ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter
          subtype: *4
        value: 
      inventory_item_id: !ruby/object:ActiveRecord::Attribute::FromDatabase
        name: inventory_item_id
        value_before_type_cast: '758'
        type: *3
        value: 758
      costing_wastage: !ruby/object:ActiveRecord::Attribute::FromDatabase
        name: costing_wastage
        value_before_type_cast: '0'
        type: *1
        value: 0.0
      pick_from_order_sheet: !ruby/object:ActiveRecord::Attribute::FromDatabase
        name: pick_from_order_sheet
        value_before_type_cast: f
        type: *5
        value: false
new_record: true

我想按create_at值排序,我在做raise object.to_yaml这个时怎么做?

推荐阅读
李桂平2402851397
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有