我想优化我的代码我该怎么做?
如果我添加了新角色,那么还会添加一个条件,但我不想要。我要任何不。角色,但我只需要一个条件可能吗?
after_save :announcement_send
def announcement_send
if self.send_now == true && self.group_id.to_s == "Artists"
User.having_role("artist").each do |user|
ArtistMailer.announcement_user(self, user).deliver
end
elsif self.send_now == true && self.group_id.to_s == "Fans"
User.having_role("fan").each do |user|
ArtistMailer.announcement_user(self, user).deliver
end
elsif self.send_now == true && self.group_id.to_s == "Both"
User.not_having_role("admin").each do |user|
ArtistMailer.announcement_user(self, user).deliver
end
end
end