The insider's guide to everything sparqcode
Header image

Actionmailer with BackgroundRb

Posted by Lee on November 25, 2009 in Technical Development - (4 Comments)

We have been working on a mailing service for a while now and we really like what we can do with html emails. Unfortunately, with the plethora of smart phones these days, HTML support is inconsistent. We figured that a good stop-gap solution was to offer both HTML and text versions of an email. Preferably in one package.

And that’s where multipart emails come in.

Suprisingly (or not), this was rather easy to implement in Rails 2.3.

There are two ways of doing this. Implicit and explicit multipart emails. I decided to go with the former.

All I had to do was to make sure the content type is set correctly:

 content_type    "multipart/alternative"

Then, I just had to make sure my template file ends with the right signature “foo.text.plain.erb” and “foo.text.html.erb” for plain text and html emails respectively.

See the multipart email section in the official doc here: http://api.rubyonrails.org/classes/ActionMailer/Base.html

I used a controller to trigger the email and it all worked just like a charm. I had my email with both text and html components. I checked in the code, fired up my mailer service which runs in backgroundrb and called it a day.

That’s when I saw this error popping up:

Message:can’t convert nil into String
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb:551:in `quote’
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb:551:in `read_multipart’
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb:540:in `parse_body_0′
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb:522:in `parse_body’
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb:476:in `body=’
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/base.rb:650:in `create_mail’
can't convert nil into String

/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb:551:in `quote'

/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb:551:in `read_multipart'

/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb:540:in `parse_body_0'

/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb:522:in `parse_body'

/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb:476:in `body='

/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/base.rb:650:in `create_mail'

...

After some investigation, I figure that this is one of those things where backgroundrb is incompatible with a certain feature of rails. I considered fudging around with the tmail code but gave up on that endeavor quickly. Instead, I decided to work around with an explicit version of the multipart email. To my delight, that worked perfectly.


part :content_type => “text/plain”,
  :body => render_message(“foo.text.plain”, :variable1=>variable1, :variable2 => variable2)
part :content_type => “text/html”,
  :body => render_message(“foo.text.html”, :variable1=>variable1, :variable2 => variable2)

Be sure to declare text/plain and text/html in that order. Email clients like Gmail may not offer the text alternative or show the HTML version automatically if you change that order.

The template files work as-is without any modifications. Well, crisis averted. Back to making some barcodes. :)

Mongrel and Snow Leopard

Posted by Lee on November 20, 2009 in Technical Development - (0 Comments)

So the ongoing saga of upgrade woes continues… You would think that “sudo gem update” should take care of upgrading all my old gems in Snow Leopard with all its 64-bit glory…

Nope.

It started when “ruby script/server” started WebBrick instead of Mongrel. That’s odd, but I figure I could work around it by just running “sudo gem install mongrel” again.

Unfortunately, that didn’t do the trick. So I tried summoning Mongrel directly:

mongrel_rails start

and I got this in return:

/Users/.../.gem/ruby/1.8/gems/mongrel-1.1.5/bin/../lib/http11.bundle: dlopen(/Users/.../.gem/ruby/1.8/gems/mongrel-1.1.5/bin/../lib/http11.bundle, 9): no suitable image found.  Did find: (LoadError)

 /Users/.../.gem/ruby/1.8/gems/mongrel-1.1.5/bin/../lib/http11.bundle: no matching architecture in universal wrapper - /Users/.../.gem/ruby/1.8/gems/mongrel-1.1.5/bin/../lib/http11.bundle

 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'

...

Luckily, Google saves the day and I found this: http://stackoverflow.com/questions/1350486/ruby-on-rails-staring-mongrel-server

I ran the following commands and it all worked as advertised. Phew, that one was easy.

sudo gem uninstall mongrel

sudo gem uninstall fastthread

sudo gem install mongrel
/Users/yowhan/.gem/ruby/1.8/gems/mongrel-1.1.5/bin/../lib/http11.bundle: dlopen(/Users/yowhan/.gem/ruby/1.8/gems/mongrel-1.1.5/bin/../lib/http11.bundle, 9): no suitable image found.  Did find: (LoadError)
/Users/yowhan/.gem/ruby/1.8/gems/mongrel-1.1.5/bin/../lib/http11.bundle: no matching architecture in universal wrapper – /Users/yowhan/.gem/ruby/1.8/gems/mongrel-1.1.5/bin/../lib/http11.bundle
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require’
from /Users/yowhan/.gem/ruby/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:12
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_requir

MSKYNET Integration With Salesforce.com

Posted by Scopes on November 18, 2009 in Press - (1 Comments)

sf-logoA leading provider of CRM solutions SCOUT has implemented a Salesforce.com offering (SPARQ Coder) that integrates our QR Code Generator API (QRGen) with Salesforce CRM applications. This free addition on the AppExchange allows Salesforce contacts, sales leads, and other personal contact information to be easily transferred from the computer screen to a mobile phone via a MeCARD QR Code.

qrgen[1]

 

MeCARD’s can be embedded dynamically to any existing webpage via a DHTML <IMG> tag that calls the QRGen API.  The rendering of the actual QR Code is in real-time and you gain the benefit of a dynamic barcode that is generated using the latest QR Code standard.  This simplifies the integration of any existing webpage to fully support dynamic QR Codes. QRGen is built with scalability in mind and is designed for integration with high volume sites that have lots of dynamically generated pages.

 

 

screen_shot

 

*UPDATE (1/19/2010) – We’re happy to update that we just found out this app was promoted as AppExchange App of the Week: on salesforce.com.

Links mentioned above
Scout Inc.
Salesforce.com
QR Code Generator API (QRGen)
SPARQ Coder – Salesforce AppExchange
AppExchange (App of the Week)

MySQL, Rails and Snow Leopard

Posted by Lee on November 18, 2009 in Technical Development - (0 Comments)

Ruby on Rails

After much hesitation, I took the dive and upgraded to Snow Leopard today. I ran into some ruby and MySQL errors, but other early adopters in our dev team had already prepared me for that. However, I would soon run into an issue that got me stumped. It turned out that I had forgotten something really simple.

So I had reinstall MySQL 64-bit and updated all my gems, but a particular mysql gem would refuse to reinstall.

There was this helpful document that several devs on my team sent me: http://stackoverflow.com/questions/991708/rails-mysql-and-snow-leopard

Unfortunately, I would get the following error even executing the recommended solution:

yowhan:~ $ sudo env ARCHFLAGS=”-arch x86_64″ gem install -V  mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config
GET 200 OK: http://gems.rubyforge.org/latest_specs.4.8.gz
GET 200 OK: http://gems.github.com/latest_specs.4.8.gz
GET 200 OK: http://gems.rubyforge.org/quick/Marshal.4.8/mysql-2.8.1.gemspec.rz
Installing gem mysql-2.8.1
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/COPYING
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/COPYING.ja
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/History.txt
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/Manifest.txt
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/README.txt
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/Rakefile
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/extconf.rb
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/mysql.c
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/extra/README.html
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/extra/README_ja.html
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/extra/tommy.css
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/lib/mysql.rb
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/tasks/gem.rake
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/tasks/native.rake
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/tasks/vendor_mysql.rake
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/test/test_mysql.rb
Building native extensions.  This could take a while…
ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lm… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lz… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lsocket… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lnsl… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lmygcc… no
checking for mysql_query() in -lmysqlclient… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.
Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
–with-mysql-config
–without-mysql-config
–with-mysql-dir
–without-mysql-dir
–with-mysql-include
–without-mysql-include=${mysql-dir}/include
–with-mysql-lib
–without-mysql-lib=${mysql-dir}/lib
–with-mysqlclientlib
–without-mysqlclientlib
–with-mlib
–without-mlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-zlib
–without-zlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-socketlib
–without-socketlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-nsllib
–without-nsllib
–with-mysqlclientlib
–without-mysqlclientlib
–with-mygcclib
–without-mygcclib
–with-mysqlclientlib
–without-mysqlclientlib
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.8.1 for inspection.

Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

sudo env ARCHFLAGS="-arch x86_64" gem install -V  mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

GET 200 OK: http://gems.rubyforge.org/latest_specs.4.8.gz

GET 200 OK: http://gems.github.com/latest_specs.4.8.gz

GET 200 OK: http://gems.rubyforge.org/quick/Marshal.4.8/mysql-2.8.1.gemspec.rz

Installing gem mysql-2.8.1

...

/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/test/test_mysql.rb

Building native extensions.  This could take a while...

ERROR:  Error installing mysql:

 ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb

...

*** extconf.rb failed ***

Could not create Makefile due to some reason, probably lack of

necessary libraries and/or headers.  Check the mkmf.log file for more

details.  You may need configuration options.

...

Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.8.1 for inspection.

Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

After several frustrating moments of poking around, a helpful fellow developer pointed out that “mysql” was not in my path. Duh!

I guess I just committed a newbie linux mistake. A quick update to .profile to include “/usr/local/mysql/bin” later, and the above command works perfectly now!

Here’s what I added to my .profile:

#Add mysql to path

export PATH=/usr/local/mysql/bin:$PATH

Hopefully that’s the last of my upgrade issues. :)

QRGen Adds HTTPS (SSL) Support

Posted by Scopes on November 17, 2009 in Announcements - (1 Comments)

ssl-logo[1] We have just launched HTTPS – Secure Sockets Layer (SSL) connectivity for our QR Code Generator API (QRGen).  This is a great addition to our popular API as we have received multiple requests to add this functionality in order to streamline the integration of our QR Code Generator with secure ecommerce sites and CRM applications.

Links mentioned above
Secure Sockets Layer (SSL)
QR Code Generator API (QRGen)

MSKYNET Enters Art Market with Gallerish

Posted by Scopes on November 13, 2009 in Press - (0 Comments)

gallerish-logo-rnd[1]Gallerish is one of the up and coming rising stars in the artwork trading space and together we are now offering a free artwork labeling service.  We are offering an easy way for artists to make labels to be displayed with their artworks that allow them to have a description, pricing, and contact information.  With SPARQCode integration it is very easy for potential clients to download artwork information instantly to their mobile phone and even browse other artworks by the same artist.

Links mentioned above
Gallerish
Artwork labeling service
SPARQCode Integration

blackberry-scan-exRIM recently launch its new BlackBerry Messenger 5.0 which has a built-in native QR Code scanner.  This scanner scans in video mode and also has the ability to render and scan BlackBerry PIN contact information.  We have received many requests to enable BlackBerry support so that users can create a BlackBerry PIN Contact barcode which they can embed in their business cards, website, or any other medium.  We are now launching our beta test for QRGen BlackBerry support and we have enhanced our QR Code generator Maestro (MeCARD) to enable BlackBerry PIN support as well.

Links mentioned above
BlackBerry Messenger 5.0 (Download)
QRGen API
Maestro (MeCARD)

Webistrano and EC2

Posted by Mitchell on November 11, 2009 in Technical Development - (2 Comments)
Our Deployment

When we first deployed our system we had a very simple Web->Database server architecture:  we had one web server talking to a single database server deployed with Webistrano.  As the site grew we quickly outgrew this setup.  We decided to build a dynamically scaling system on top of Amazon EC2 to make sure we would never have to worry about adding or removing hardware.

Our EC2 system will spin up and spin down web servers based on a set of metrics that we collect on a continuous basis.  This presents some fairly interesting challenges with Webistrano.  While Webistrano provides a great set of features it’s obviously designed for deploying to a fixed set of servers.

We looked at a variety of options for deployment but we wanted to stick with Webistrano for the following reasons:

  1. Convenient central store for recipes
  2. Easy integration into our source control system
  3. Tracked and repeatable deployments

We are also firm believers in not reinventing the wheel, so how did we work around the static nature of Webistrano?  We leveraged the power of open source :)  We added a RESTful API call to Webistrano that allows a remote host to add or remove an ip address to a Webistrano deployment stage.

Each instance of our application has a backgroundrb task that hits this web service every minute.  Consequently the list of active servers is always up to date.  Not only that, but when our images start up they will deploy the latest released version of the code.  How do we deal with servers that die?  We added a Webistrano backgroundrb job that that removes hosts that have not been updated within the last five minutes.

What does all this mean?  Our deployments always go to our currently active servers and our system scales on demand.

QRGen Firefox Add-on

Posted by Scopes on November 10, 2009 in Press - (0 Comments)

firefox_logo[1]We recently discovered an interesting use of our QR Code Generator API (QRGen) for a Firefox add-on called Easy QR code.  It is basically a simple utility that allows you to quickly create raw QR Codes in the Firefox browser.  The codes generated in the browser can be easily downloaded or saved as a file locally.  This add-on was developed by megszokot.

 

ff_EasyQR_screenshot[1]

 

Links mentioned above
QRGen API
Easy QR code (Firefox add-on)
megszokot (developer of Easy QR code)

SPARQCode Launch!

Posted by Scopes on November 7, 2009 in Press - (0 Comments)

SPARQLogoMSKYNET is launching the new SPARQCode™ website that is fully dedicated to mobile consumers.  We have decided to spin off the SPARQCode site as a landing place for regular mobile users to discover and learn about 2d barcodes.  The MSKYNET site will continue be the home of our business solutions and we look forward to the many upcoming product launches and press releases that will be coming soon.

Links mentioned above
SPARQCode (site for mobile users)