1

我希望能够上传 vcard 并将其解析到我的应用程序的模型中。

我认为 Paperclip 将是一种上传方式,但我不知道如何进行解析。

我在 google 上进行了搜索,似乎唯一相关的库是 vpim,评论不一。

想看看有什么绝妙的想法可以解决这个问题……谢谢。

4

2 回答 2

3

vpim是制作和导入 vCard 的有用 gem,这里是如何使用它...

gem 'vpim', '~> 13.11.11' #include this in your gemfile

在您的控制器中解码 vcard

@vcard = Vpim::Vcard.decode(params[:import_file].read)

@contact.title = @vcard.title
@contact.email = @vcard.email
@contact.first_name = @vcard.name.given
@contact.last_name = @vcard.name.family
@contact.phone = @vcard.telephones[0]
@contact.fax = @vcard.telephones[1]
@contact.address.street1 = @vcard.address.street
@contact.address.city = @vcard.address.locality
@contact.address.state = @vcard.address.region
@contact.address.zip = @vcard.address.postalcode
@contact.company_name = @vcard.org.fetch(0)

您可以使用的另一个宝石是vcardigan

于 2014-06-02T21:04:22.703 回答
1

使用 vpim 解决了它

于 2010-05-25T19:35:25.997 回答