i*****r 发帖数: 26 | 1 有什么地方需要修改的吗?
Given a piece of code, what comments would you have for the author?
# Provides CRUD methods for “Contact” records
# - Name MUST be provided
# - Email Addresses MUST be unique class ContactLogic
我写的如下
def self.create(name, email_addresses, description) contact = Contact.new
contact.name = name
contact.description = description
email_addresses.each do |address|
contact.email_addresses << address
if Contact.where(:email_address => address).present?
raise “Cannot duplicate email addresses”
end
end
contact.save!
return contact
end
def self.update(id, name, email_addresses, description)
contact = Contact.find(id)
contact.name = name
contact.description = description
email_addresses.each do |address|
contact.email_addresses << address
if Contact.where(:email_address => address).present?
if Contact.where(:email_address => address).first.id !=id
raise “Cannot duplicate email addresses”
end
end
end
contact.save!
return contact
end
end | a*******g 发帖数: 1221 | | i*****r 发帖数: 26 | 3 谢谢提醒,已排版
【在 a*******g 的大作中提到】 : 排下版吧
|
|