tap/app/models/product.rb

30 lines
985 B
Ruby
Raw Normal View History

# == Schema Information
#
# Table name: products
#
# id :integer not null, primary key
# name :string(255)
# purchase_price :integer
# sale_price :integer
# created_at :datetime
# updated_at :datetime
# avatar_file_name :string(255)
# avatar_content_type :string(255)
# avatar_file_size :integer
# avatar_updated_at :datetime
#
2014-11-24 21:45:32 +01:00
class Product < ActiveRecord::Base
has_many :order_products
has_attached_file :avatar, styles: { medium: "100x100>" }, default_style: :medium
validates :name, presence: true
validates :purchase_price, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :sale_price, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates_attachment :avatar, presence: true, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
2014-12-08 11:41:38 +01:00
def count(order)
order_products.find_by(order: order).count
end
2014-11-24 21:45:32 +01:00
end