Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Community < ActiveRecord::Base
- has_many :community_invitation_notices, :class_name => "CommunityInvitationNotice", :as => :sender
- after_save :save_community_invitation_notices
- def new_community_invitation_notices=attributes
- attributes.each_pair { |key,values|
- self.community_invitation_notices.build(values) unless values[:delete].to_i == 1 # Don't send to people not invited
- }
- end
- private
- def save_community_invitation_notices
- self.community_invitation_notices.each { |i|
- (i.delete.to_i == 1)? i.destroy : i.save
- }
- end
- end
- class Notice < ActiveRecord::Base
- belongs_to :sender, :polymorphic => true
- belongs_to :recipient, :polymorphic => true
- attr_accessor :delete
- end
- class CommunityInvitationNotice < Notice
- belongs_to :sender, :as => :community, :polymorphic => true
- attr_accessor :user_id
- after_save :save_user_id
- def user_id=i
- puts "SETTING USER_ID #{i}"
- self.recipient_id = i
- self.recipient_type = "User"
- end
- private
- def save_user_id
- puts "CALLING AFTER SAVE"
- end
- end
Add Comment
Please, Sign In to add comment