Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Class Item
- class Item < ActiveRecord::Base
- #An item belongs to an account and a group
- belongs_to :group
- #belongs_to :account
- #An item has many locations
- #has_many :locations
- #Validations of attributes, such as presence and length
- validates :code, :length => {maximum => 45}
- validates :name, :length => {maximum => 45}
- validates :description, :length => {maximum => 255}
- validates :status, :length => {maximum => 45}
- validates :visibility, :presence => true
- #Constructor method
- def initializer(visibility)
- @visibility = visibility
- end
- end
- ----
- #Class Location
- class Location < ActiveRecord::Base
- #A location belongs to an account
- belongs_to :account
- #A location has many items
- has_many :items
- #Validations of presence
- validates :latitude, :presence => true
- validates :longitude, :presence => true
- validates :date, :presence => true
- validates :account_id, :presence => true
- #Constructor method
- #Olhar essa account_id se a "location" pertence a "account", acho que deveria ser o contrário - by Souza
- def initiliazer(latitude, longitude, date, account_id)
- @latitude = latitude
- @longitude = longitude
- @date = date
- @account_id = account_id
- end
- end
- --
- #Class Account
- class Account < ActiveRecord::Base
- #An account has many locations
- has_many :locations
- #An account has many items
- has_many :items
- #Validations of attributes, such as presence and length
- validates :username, :presence => true, :length => {:maximum=>45}
- validates :password, :presence => true, :length => {:minimum=>6,:maximum=>45}
- validates :role, :presence => true, :length => {:maximum=>45}
- #Constructor method
- def initializer(username, password, role)
- @username = username
- @password = password
- @role = role
- end
- end
- ---
- #class Group
- class Group < ActiveRecord::Base
- #Association of 0 to many
- has_many :items
- #Validates presence of name and length (maximum length is 45)
- validates :name, :presence => true, :length => {:maximum => 45}
- #Constructor method
- def initializer(name)
- @name = name
- end
- end
Add Comment
Please, Sign In to add comment