멀티 레일 이메일 연결 등을 포함하는 iphone contact과 일치하도록 레일스 모델 스키마를 만들었습니다. 전체 주소록 배열을 가져 오는 컨트롤러 작업이 있습니다. 여러 전자 메일 개체 포함). 상당히 효율적으로 실행하려면이 필요합니다. 그래서 배치 가져 오기 activerecord-import 찾고있었습니다. 그러나 각 컨택의 범위 내에서 전자 메일의 고유성을 확인하여 일괄 처리를 가져올 때마다 중복을 계속 추가하지 않아야합니다. 수작업으로 직접 update_attributes
의 자체 버전을 구축해야합니까, 아니면 이와 같은 많은 레코드의 유효성을 검사/업데이트 할 때 권장 할만한 기존 솔루션이 있습니까?iphone 주소록을 레일스와 동기화하기
연락 모델
class Contact > ActiveRecord::Base has_many :addresses has_many :emails has_many :websites accepts_nested_attributes_for :addresses, :emails, :websites attr_accessible :prefix, :first_name, :middle_name, :last_name, :suffix, :nickname, :organization, :job_title, :department, :birthday, :addresses_attributes, :emails_attributes, :websites_attributes end
이메일 모델
class Email > ActiveRecord::Base belongs_to :contact # validates_uniqueness_of :account, :scope => :contact_id # prevents duplicate, but also skips sibling values # validates :contact_id, :presence => true, :on => :create # causes 422 error validates :account, :presence => true, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create attr_accessible :contact_id, :email_id, :account, :label end
매우 도움이됩니다. 감사합니다. 나는 지금 당장 서버에 내 자신의 메서드를 굴렸다. 결국 클라이언트에서 유효성 검사를 시도하고 그 당시 activerecord-import를 시도합니다. –