How to Add Electronic Business Card in Rails App
What is vCard ?
vCard is a file format standard for electronic business cards. vCards are often attached to e-mail messages, it can also be exchanged through a webapp or instant messaging.
Why Virtual Business Card?
- You can update your contact details easily.
- Integrates easily with contact management applications.
- Provide a link to anyone to add your contact details with just a few clicks.
- Avoid mistakes in entering phone number, email etc.
- You don't need to install any mobile app
- You don't need to be in the same OS or platform as your contact
Rails already comes with vcf mime type defined in
rails/actionpack/lib/action_dispatch/http/mime_types.rb as shown below:
Mime::Type.register "text/vcard", :vcf
If the version of Rails you are using does not have it. You can add the mime-type for vcards in config/initializers/mime_types.rb:
Mime::Type.register 'text/x-vcard', :vcf
Add a link to download the vCard in the view:
<%= link_to("Download vcard", download_vcard_path(:format => 'vcf')) %>
Define a route in routes.rb:
get 'vcard', to: 'welcome#download_vcard', :as => :download_vcard
Add an action to process the vCard request in welcome controller:
def download_vcard respond_to do |format| format.vcf do tmp_file = open('https://www.rubyplus.com/bparanj.vcf') send_data tmp_file.read, :filename => 'bparanj.vcf', :type => :vcf end end end
In my case, the bparanj.vcf file is in the public folder of my Rails app. The contents are as follows:
BEGIN:VCARD VERSION:4.0 N:Paranj;Bala;;Mr; FN:Mr Bala Paranj TITLE:Software Engineer PHOTO;TYPE=uri:https://images.rubyplus.com/me.jpg EMAIL:firstname.lastname@example.org ORG:RubyPlus TEL:4048615540 URL;type=pref:https://www.rubyplus.com ADR:;2484 Briarcliff Road, 22-119;;Atlanta;GA;30329;USA END:VCARD
You can customize the above file by replacing my details with your contact details. Now the download link will add the contact to your contact list as a contact in your Mac, Android device etc. You can test this feature by clicking on the 'Download vCard' link on the RubyPlus Contact page. You can also download my virtual business card by clicking Bala Paranj Virtual Business Card. I can paste the link to vCard in instant messaging systems, email signature etc to share my contact details easily. This makes it very easy for your potential professional networking person to add you to their contact list.
Virtual Business Card HTML
You can also add html for vcard like this:
<div class="vcard"> <span class="fn"><span class="given-name">Bala</span> <span class="family-name">Paranj</span></span>, <span class="title">Senior Copy Paster</span>, <div class="org">RubyPlus</div> <div class="adr"> <div class="street-address">2484 Briarcliff Road, #22-119</div> <span class="locality">Georgia</span>, <span class="region">Atlanta</span> <span class="postal-code">30329</span> </div> <div>Phone: <span class="tel">4048615540</span></div> <div>Email: <span class="email">email@example.com</span></div> </div>
Anyone can open the vcf file and they can import it to their contact list.
The details of the contact for rubyplus.com contact page is shown below:
In this article, you learned how easy it is to add a virtual business card in a Rails app. It makes it easier to update and share your contact information with others.