Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. class EmergencyContact < ActiveRecord::Base
  2. attr_accessible :full_name, :relationship, :mobile_phone, :student_id
  3. belongs_to :student
  4.  
  5. validates :full_name, :presence => true
  6. validates :relationship, :presence => true
  7.  
  8. end
  9.  
  10. Student Name: _____________
  11.  
  12. Emergency Contacts
  13. ------------------------------------------
  14. | Name | Relationship |
  15. ------------------------------------------
  16. | | |
  17. ------------------------------------------
  18. | | |
  19. ------------------------------------------
  20. | | |
  21. ------------------------------------------
  22.  
  23. class Student < ActiveRecord::Base
  24. has_many :emergency_contacts
  25. accepts_nested_attributes_for :emergency_contacts,
  26. :reject_if => lambda { |a| a[:full_name].blank? }
  27. end
  28.  
  29. proc { |attributes|
  30. attributes.delete :_destroy
  31. attributes.reject { |key, value| value.blank? }.empty?
  32. }
  33.  
  34. accepts_nested_attributes_for :emergency_contacts, :reject_if => :all_blank
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement