This is the key line for the fix.  Most of the other work was cleanup to avoid duplicate code (especially since it may need to be updated as the rails api evolves).