Hi,
I want to generate a single .vcf file with several contacts, but I can't because vpim generates it like a unique contact .vcf with other users data.
This is my code for generate a single contact vcard and works fine:
def get_card
contact = User.find(params[:id]) card = Vpim::Vcard::Maker.make2 do |maker|
maker.add_name do |name| name.given = contact.user_info.name end
maker.add_addr do |addr| addr.location = 'home' addr.street = contact.user_info.address_street addr.locality = contact.user_info.address_city addr.region = contact.user_info.address_state addr.postalcode = contact.user_info.address_postalcode end
if !contact.user_info.telephone.empty? maker.add_tel(contact.user_info.telephone) do |tel| tel.location = 'home' tel.preferred = true end end
if !contact.user_info.fax.empty? maker.add_tel(contact.user_info.fax) do |tel| tel.location = 'home' tel.capability = 'fax' end end
maker.add_email(contact.email) do |e| e.location = 'home' end end
send_data card.to_s, :filename => contact.user_info.name + ".vcf" end
And this is my method for a single vcard file with multiple contacts:
def get_list_cards ids = params[:ids] contact_list = card = Vpim::Vcard::Maker.make2 do |maker| ids.each do |id| contact_list.push(User.find(id)) end contact_list.each do |contact| #I need to introduce BEGIN:VCARD tag to separate contacts maker.add_name do |name| name.given = contact.user_info.name end
maker.add_addr do |addr| addr.location = 'home' addr.street = contact.user_info.address_street addr.locality = contact.user_info.address_city addr.region = contact.user_info.address_state addr.postalcode = contact.user_info.address_postalcode end
if !contact.user_info.telephone.empty? maker.add_tel(contact.user_info.telephone) do |tel| tel.location = 'home' tel.preferred = true end end
if !contact.user_info.fax.empty? maker.add_tel(contact.user_info.fax) do |tel| tel.location = 'home' tel.capability = 'fax' end end
maker.add_email(contact.email) do |e| e.location = 'home' end end #I need to introduce END:VCARD tag to separate contacts end send_data card.to_s, :filename => params[:name]+".vcf" end
It works but not well, it generates .vcf file but with a single N:; tag. I need to add as N:; tags as user names and i need to split each contact with BEGIN:VCARD and END:VCARD. I don't know how to do it.