Sha256: 78288aea1c96b503294a5b5281d5ffe6eef04f1f6d101c39289f191e9757f72d

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

module RailsMarketplace
	class Product < ActiveRecord::Base
		include FriendlyId
		friendly_id :title, :use => :slugged
		monetize :price_cents, :allow_nil => true
		
		has_many :category_products, :dependent => :destroy, :autosave => true , :inverse_of => :product
		accepts_nested_attributes_for :category_products, :allow_destroy => true, :reject_if => :all_blank
		has_many :categories, :through => :category_products

		belongs_to :seller

		has_many :cart_products
		has_many :carts, :through => :cart_products
		
		has_many :order_products
		has_many :orders, :through => :order_products

		serialize :images, JSON
		serialize :files, JSON
		mount_uploaders :images, ProductImagesUploader
		# mount_uploaders :files, ProductFilesUploader

		validates :title, :presence => true
		validates :images, :presence => true
		validates :price, :presence => true
		validates :quantity, :presence => true
		# validates :files, :presence => true

		def should_generate_new_friendly_id?
		  title_changed?
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails_marketplace-0.0.2 app/models/rails_marketplace/product.rb
rails_marketplace-0.0.1 app/models/rails_marketplace/product.rb