Monday, November 18, 2013

Setting cell color using Ruby spreadsheet GEM

I've recently been working on a Rails project and needed to output some data in spreadsheet format.  My client wanted some simple styling of the spreadsheet but the standard colors didn't seem to fit the bill.  That's when I discovered that there are other options besides :red, :blue, :green, :cyan, etc. for the background style on a spreadsheet cell using the spreadsheet GEM.   Although I couldn't find any reference to these additional colors it is obvious from looking through the source code for the GEM that they exist.  Unfortunately, the symbol names used to represent these "additional" colors didn't lend themselves very well to visualize what color they represented.  They are :xls_color_0, :xls_color_1, etc...  and you can see them by looking at the source code here.

So I decided to output a quick spreadsheet with cell text representing the symbol name and then formatting the cell background with the color.   This makes a handy reference for those colors as well as providing some examples of how to format a cell.  Here's the source code:

The Gist is here.

The program  will output a file colors.xls that looks like the following:


Thursday, November 7, 2013

Capistrano deploy fails with gem hosted on GitHub.com

A college of mine and I recently upgraded on of our side projects from a Rails 3 and ruby 1.9.3 to Rails 4 and ruby 2.0.  In the course of doing so we needed to ensure that all the dependent GEM's we are using were Rails 4 and ruby 2.0 compatible.   As is usually the case someone had done the leg work and although not all of the core projects were updated, he was able to find forks on the original projects that had done the upgrades.

Today I was finally getting around to making sure the the application could still deploy to our staged environment.  Unfortunately it was failing.  I use Capistrano for the deployment and I was seeing it fail to clone the one of these GitHub hosted, upgraded GEMs my college found.  The error was:

Permission denied (publickey).
fatal: The remote end hungh up unexpectedly
Git error: command `git clone 'git@github.com:tsmango/default_value_for.git'



I immediately tried to clone the project from my terminal window and all worked fine.  I thought, GitHub.com must be having an issue but upon checking that out on the status page they were not reporting any issues at all.  If I had paid more attention to the details all the clues I needed where right there in front of me but the actual problem still didn't dawn on me until I looked up this post.

Turns out the our GEMFILE needed to reference the non-SSH read-only URL for the projects so that I didn't need to authenticate with ssh.

Changed the entry in my GEMFILE from:

gem 'default_value_for', :git => 'git@github.com:tsmango/default_value_for.git'

to:

gem 'default_value_for', :github => 'tsmango/default_value_for'

Once that change was made bundle install was required but then I was able to successfully deploy our application.

Hopefully this saves someone else a few minutes of time troubleshooting similar errors.