Quantcast
Viewing all articles
Browse latest Browse all 10

Using ERB as a dynamic template to create a file whose contents are dynamic

The following code will create a temporary file for say attaching a vcard file to email.The following code is dynamic to use ERB as a template to create the file dynamically every time with the variable “telephone”,”location”,”email” which gets binded to the ERB file and is under scope.
The code is:-

{
telephone = “347-27456″
location = “New Delhi”
email = “xyz@gmail.com”
vcard = ERB.new( File.open(‘address.vcard.erb’ ){ |f| f.read } ).result( binding )
f = File.new(“temp_file.vcf”,”wb”)
f.puts vcard
f.close
}

and in pastie is here


Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 10

Trending Articles