Advertisement
Guest User

Untitled

a guest
Jan 27th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. create_table :students, :id => false do |t|
  2. t.integer "student_id", :auto_increment => true, :primary_key => true
  3. t.string "first_name", :limit => 25
  4. t.string "last_name", :limit => 50
  5. t.string "email", :default => ' ', :null => false
  6. t.string "birthday"
  7. t.string "subjects"
  8. t.string "username", :limit => 25
  9. t.string "password_digest"
  10. t.timestamps
  11. end
  12.  
  13. create_table :teachers, :id => false do |t|
  14. t.integer "teacher_id", :auto_increment => true, :primary_key => true
  15. t.string "first_name"
  16. t.string "last_name"
  17. t.string "email", :default => ' ', :null => false
  18. t.string "birthday"
  19. t.string "subjects"
  20. t.string "username", :limit => 25
  21. t.string "password_digest"
  22. t.timestamps
  23. end
  24.  
  25. class Student < ApplicationRecord
  26.  
  27. has_many :subjects, through: :enrolled_subjects
  28. has_many :teachers, through: :enrolled_subjects
  29.  
  30. def teacher_names
  31. self.teachers.map(&:name).join(", ")
  32. end
  33.  
  34. has_many :admin_users
  35. has_secure_password
  36. self.primary_key = :student_id
  37.  
  38.  
  39. scope :newest_first, lambda { order("created_at ASC") }
  40. scope :oldest_first, lambda { order("created_at DESC") }
  41. # scope :search, lambda { |query| where(["name LIKE ?", "%#{query}%"])}
  42.  
  43. end
  44.  
  45. class Teacher < ApplicationRecord
  46.  
  47. has_many :subjects, through: :enrolled_subjects
  48. has_many :students, through: :enrolled_subjects
  49. has_many :admin_users
  50. has_secure_password
  51.  
  52. scope :newest_first, lambda { order("created_at ASC") }
  53. scope :oldest_first, lambda { order("created_at DESC") }
  54. # scope :search, lambda { |query| where(["name LIKE ?", "%#{query}%"])}
  55. end
  56.  
  57. class Subject < ApplicationRecord
  58.  
  59. has_many :students, through: :enrolled_subjects
  60. has_many :teachers, through: :enrolled_subjects
  61. has_many :admin_users
  62.  
  63. # scope :search, lambda { |query| where(["name LIKE ?", "%#{query}%"])}
  64.  
  65. end
  66.  
  67. class EnrolledSubject < ApplicationRecord
  68. belongs_to :student
  69. belongs_to :subject
  70. belongs_to :teacher
  71. end
  72.  
  73. class AdminUser < ApplicationRecord
  74.  
  75. has_secure_password
  76.  
  77. scope :newest_first, lambda { order("created_at ASC") }
  78. scope :oldest_first, lambda { order("created_at DESC") }
  79. # scope :search, lambda { |query| where(["name LIKE ?", "%#{query}%"])}
  80. end
  81.  
  82. stud = Student.create(:student_id => 1, :first_name => 'Jos', :last_name => 'Norton', :email => 'ss.norton@gmail.com', :birthday => '12/05/1995', :subjects => 'English', :username => 'samnorton2', :password => 'Grace02112')
  83.  
  84. ERROR:
  85.  
  86. NoMethodError: undefined method `each' for "English":String
  87.  
  88. SyntaxError: /Users/mac/Sites/STMS/db/migrate/20170124125144_create_students.rb:10: syntax error, unexpected ':', expecting keyword_end
  89. t.string :subjects, :array: true, default: []
  90. ^
  91. /Users/mac/Sites/STMS/db/migrate/20170124125144_create_students.rb:10: Can't assign to true
  92. t.string :subjects, :array: true, default: []
  93.  
  94. <% @students.each do |student|%>
  95. <%= student.subjects %>
  96. <% end %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement