Guest User

Untitled

a guest
Jun 7th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #Class Item
  2.  
  3. class Item < ActiveRecord::Base
  4. #An item belongs to an account and a group
  5. belongs_to :group
  6. #belongs_to :account
  7. #An item has many locations
  8. #has_many :locations
  9.  
  10. #Validations of attributes, such as presence and length
  11. validates :code, :length => {maximum => 45}
  12. validates :name, :length => {maximum => 45}
  13. validates :description, :length => {maximum => 255}
  14. validates :status, :length => {maximum => 45}
  15. validates :visibility, :presence => true
  16.  
  17.  
  18. #Constructor method
  19. def initializer(visibility)
  20.  
  21. @visibility = visibility
  22.  
  23. end
  24. end
  25.  
  26.  
  27. ----
  28. #Class Location
  29. class Location < ActiveRecord::Base
  30.  
  31. #A location belongs to an account
  32. belongs_to :account
  33. #A location has many items
  34. has_many :items
  35.  
  36. #Validations of presence
  37. validates :latitude, :presence => true
  38. validates :longitude, :presence => true
  39. validates :date, :presence => true
  40. validates :account_id, :presence => true
  41.  
  42. #Constructor method
  43. #Olhar essa account_id se a "location" pertence a "account", acho que deveria ser o contrário - by Souza
  44. def initiliazer(latitude, longitude, date, account_id)
  45.  
  46. @latitude = latitude
  47. @longitude = longitude
  48. @date = date
  49. @account_id = account_id
  50.  
  51. end
  52.  
  53. end
  54.  
  55.  
  56. --
  57. #Class Account
  58.  
  59. class Account < ActiveRecord::Base
  60.  
  61. #An account has many locations
  62. has_many :locations
  63. #An account has many items
  64. has_many :items
  65.  
  66. #Validations of attributes, such as presence and length
  67. validates :username, :presence => true, :length => {:maximum=>45}
  68. validates :password, :presence => true, :length => {:minimum=>6,:maximum=>45}
  69. validates :role, :presence => true, :length => {:maximum=>45}
  70.  
  71. #Constructor method
  72. def initializer(username, password, role)
  73.  
  74. @username = username
  75. @password = password
  76. @role = role
  77.  
  78. end
  79. end
  80.  
  81.  
  82. ---
  83. #class Group
  84.  
  85. class Group < ActiveRecord::Base
  86.  
  87. #Association of 0 to many
  88. has_many :items
  89. #Validates presence of name and length (maximum length is 45)
  90. validates :name, :presence => true, :length => {:maximum => 45}
  91.  
  92. #Constructor method
  93. def initializer(name)
  94.  
  95. @name = name
  96.  
  97. end
  98.  
  99.  
  100. end
Add Comment
Please, Sign In to add comment