Attributes
attribute
define_attribute# db/schema.rb
create_table :store_listings, force: true do |t|
t.decimal :price_in_cents
end
# app/models/store_listing.rb
class StoreListing < ActiveRecord::Base
end
store_listing = StoreListing.new(price_in_cents: '10.1')
# before
store_listing.price_in_cents # => BigDecimal.new(10.1)
class StoreListing < ActiveRecord::Base
attribute :price_in_cents, Type::Integer.new
end
# after
store_listing.price_in_cents # => 10最后更新于