added suppliers, weight to item

This commit is contained in:
Senad Uka
2015-03-14 06:33:49 +01:00
parent 0bafbb4b2f
commit e7793f0884
17 changed files with 304 additions and 2 deletions

View File

@@ -1,2 +1,6 @@
class Cart < ActiveRecord::Base
has_many :item_in_carts
belongs_to :user
end

View File

@@ -2,6 +2,9 @@ class Item < ActiveRecord::Base
belongs_to :unit
has_many :multi_media_descriptions
belongs_to :sub_category
belongs_to :supplier
validates_presence_of :name, :description, :list_price, :current_input_price, :tags, :unit_id, :code, :sub_category_id, :weight, :supplier_id
validates_presence_of :name, :description, :list_price, :current_input_price, :tags, :unit_id, :code, :sub_category_id
end

View File

@@ -5,4 +5,8 @@ class ItemInCart < ActiveRecord::Base
validates_uniqueness_of :item_id, scope: :cart_id
validates :item_id, presence: true
validates :cart_id, presence: true
def to_s
item.name + " " + count.to_s + " " + price.to_s
end
end

View File

@@ -0,0 +1,6 @@
class Supplier < ActiveRecord::Base
has_many :items
validates_uniqueness_of :name
validates_presence_of :name
end

View File

@@ -0,0 +1,10 @@
class User < ActiveRecord::Base
has_many :carts
validates_presence_of :first_name, :last_name, :password, :email, :password_confirmation
validates :email, :uniqueness => {:case_sensitive => false, :message => "Email already exists!"},
format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, message: "invalid email" }
validates :password, confirmation: true, length: { in:6..20, too_short: 'password needs to be at least 6 characters long' }
end