Guest User

Untitled

a guest
Feb 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. class Community < ActiveRecord::Base
  2. has_many :community_invitation_notices, :class_name => "CommunityInvitationNotice", :as => :sender
  3. after_save :save_community_invitation_notices
  4.  
  5. def new_community_invitation_notices=attributes
  6. attributes.each_pair { |key,values|
  7. self.community_invitation_notices.build(values) unless values[:delete].to_i == 1 # Don't send to people not invited
  8. }
  9. end
  10.  
  11. private
  12. def save_community_invitation_notices
  13. self.community_invitation_notices.each { |i|
  14. (i.delete.to_i == 1)? i.destroy : i.save
  15. }
  16. end
  17. end
  18.  
  19. class Notice < ActiveRecord::Base
  20. belongs_to :sender, :polymorphic => true
  21. belongs_to :recipient, :polymorphic => true
  22. attr_accessor :delete
  23.  
  24.  
  25. end
  26.  
  27.  
  28. class CommunityInvitationNotice < Notice
  29. belongs_to :sender, :as => :community, :polymorphic => true
  30. attr_accessor :user_id
  31.  
  32. after_save :save_user_id
  33.  
  34. def user_id=i
  35. puts "SETTING USER_ID #{i}"
  36. self.recipient_id = i
  37. self.recipient_type = "User"
  38. end
  39.  
  40. private
  41.  
  42. def save_user_id
  43. puts "CALLING AFTER SAVE"
  44. end
  45.  
  46. end
Add Comment
Please, Sign In to add comment