FAILSAFE “bad content type” when POSTing multipart data in Rails

My coworker and I spent way too much time on this issue.

The task: Post an image from a Flash/ActionScript frontend to a Rails controller, populating an attachment_fu model. After several attempts, we kept getting the same result: A FAILSAFE error (”bad content type”) called from read_multipart. Here is the stack trace:

The controller’s create action simple populates the appropriate file field like so:
@dog_image.uploaded_data = params[:dog_image]

So what was going on? Well, the “bad content type” message was informative, but barely so. It turns out that the multipart data being POSTed from the SWF was malformed, and Rails didn’t like that. Only one of the many ActionScript multipart libraries seems to use proper formatting, and that one is MultipartURLLoader, as described in this post.

I had to write this post in the hopes that someone will benefit from it, as it took many hours of research to figure this out!


Fun with script/console: Ever tried app.get?

I came across a reference to a script/console session that looked like this:

Sweet. I had never heard of ActionController::Integration::Session, but now this little gem will be a regular tool for me for testing controller requests.

Submitting a Rails documentation patch for rescue_from

The existing documentation for Rails’ rescue_from is lacking in my opinion.

Intuitively, I thought that the following was a simple enough setup:

I was wrong. My thought was that just like rescue blocks, the more specific instances of the Exception should be listed first, followed by more generic Exception classes (perhaps finishing with StandardError should you want a catch-all handler). In fact, the exact opposite ordering is used: The more generic Exception classes should be listed first, followed by more specific classes. Listing a superclass such as StandardError first actually precludes other handlers from running.

Thanks to this comment on ApiDock for the guidance. I have requested access to lifo’s Rails documentation repo on github so that I can commit a docpatch.  I also plan to include in the docpatch a better usage example that shows off the rescuing of multiple exception types in one declaration, like so:

Stay tuned…

A handy monkey-patch: Add to_xml to Ruby’s StandardError

While working on some error handler refactoring in a Rails app, I added this bit of code to my application controller (application.rb):

Then I found that the method StandardError#to_xml that I expected to be defined, actually was not. So I put this into an initializer:

Itch scratched!

Taco Tournament - Round 1 Results

I forget the source, but I somehow came across this blog post on lataco.com.  A tournament of tacos from LA’s best tacquerias:  I had to participate.

My type of tournament

My type of tournament

Work got in the way of participating in the actual event, so a few of us from SocialVibe finally got our act together and picked a few accessible taquerias to compete in a Friday morning Taco Royal Rumble.

The contenders for our first round:  Tito’s Tacos, Tacomiendo, Tacos Por Favor, and El Taurino.

When the contenders arrived at work this morning, we took over the sales desks, setting up a taco picnic.

Taco Picnic

Taco Picnic

The four of us judges (@findchris, @jessealbini, @hapaboy, and @countzen) each took one taco from each contender, and did some synchronized tasting.

Tacos Por Favor

First on the tasting menu was Tacos Por Favor.  See for yourself:

Tacos Por Favor

Tacos Por Favor

These were a strong opener, and a great basic taco.  That’s what we thought until we tried…

El Taurino

Contrasted with Tacos Por Favor, El Taurino’s tacos had a more complex flavor palette.  There is a subtle lime note that really added to the overall flavor profile.  These carne asada tacos needed no salsa beyond the light drizzle of salsa roja applied by default.

El Taurino

El Taurino

Tacos Por Favor were good, but only after contrasting them with El Taurino did the judges unanimously agree that El Taurino had the better asada taco.

Tacomiendo

Tacomiendo

Tacomiendo

After tasting the perfectly complete flavor profile of the El Taurino tacos, the completely plain asada tacos from Tacomiendo seemed a hopeless contender.  The flavor of the carne asada alone was surprisingly good, enhanced further by some salsa verde.  Although the taco as a whole could not defeat El Taurino, the judges agreed that the meat from Tacomiendo was the best of the lot.

Tito’s Tacos

DISCLOSURE:  I grew up in Culver City and have always loved the distinct fried corn tortilla shell of Tito’s, despite a strong and vocal anti-Tito’s contingent (see the Yelp reviews).  The chips and salsa from Tito’s stand out from the lightweight and unremarkable selection in the field, although we (the Taco judges) were not going to be making any decisions based on chips.

One look at tacos from Tito’s reveals that these are not your traditional Mexican soft taco.  The soft, shredded beef is fried inside of the corn tortilla shell, locking in flavor and juices.  Shredded iceberg lettuce and lots of coarsely shredded cheese top each taco.

Tito's Tacos

Tito's Tacos

I personally consider it a requirement to put a ton of Tito’s blended salsa on top of each taco, as the stuff is so tasty you can literally drink it (I have been known to do this upon occasion).

The Votes

Although they look like something from Taco Bell, three of the four taco judges voted Tito’s “best tasting”, with one judge giving his vote to El Taurino.  Everyone agreed that the award for “Most Classic Mexican Taco” went to El Taurino.

Who knows when Taco Tournament Round 2 will occur, but results will be posted here.

For another good resource on LA’s taco’s, check out http://tacohunt.blogspot.com.

One of the iPhone’s worst itches to be scratched, finally

I’ve said it once (maybe more) and I’ll say it again: I love the iPhone, but I hate AT&T.  Having a pocket-sized computer on me at all times has proven so valuable that I, and my wife, are willing to deal with AT&T’s awful mobile network.

But this isn’t about AT&T (perhaps another post?); this is all about the iPhone.  Despite being a gift from the digital goods gods, the iPhone does have, as many have noted, some serious shortcomings.  People say that copy and paste and turn by turn directional navigation are two features that are notably missing; I agree.  However, the features most notably missing from the iPhone are those embedded in every other mobile device on the market, from the Blackberry on down to the Kyocera you get for free with the cheapest cellular plan.

This past weekend provided a great example of how noticably deficient the iPhone for basic mobile utility.  My wife’s friend recently had a baby, and so snapped a baby picture on her mobile phone, and sent out a text message with the picture attached.  This is known as an MMS or “Multimedia Messaging Service” message.  So the baby was cute, right?  Who knows.  We couldn’t see the picture.  Instead, AT&T sent us a text message that looks like this:

When good picture messages go bad.

Horrid, isn’t it?  It wouldn’t be so bad if AT&T appended the “MSG ID” and “Password” values to the URL so that you could automatically click through to your message, but that is not the case.  So you go to www.viewmymessage.com/2 and this is what you see:

Worst user experience ever.

Worst user experience ever.

Again, a terrible experience.  How am I supposed to remember the “MSG ID” and “Password” when they are strings like “y1jqtectd”?!  Despite numerous attempts at viewing the picture message, my wife and I kept entering the wrong “MSG ID” and “Password”, or more likely, AT&T is evil and swallowed the baby picture.  So I still haven’t seen this baby picture, and it’s thanks to Apple and AT&T.

Ok, the bitching ends there.  With the announcement of the iPhone firmware 3.0 to be released in the not-too-distant future, it looks like the MMS woe will be resolved, along with myriad other upgrades.  Mobile email may very well obviate MMS messages, but in the meanwhile being able to see a picture of a friend’s baby makes MMS an important feature indeed.

Rails plugin mysql_replication_adapter for Rails 2.2+

Just a quick post to make available to the internet that I’ve updated the mysql_replication_adapter gem/plugin to be compatible with Rails 2.2+.

The original mysql_replication_adapter was first made available by RapLeaf.  It was a gem that was released in mid-2007 and hosted on rubyforge.  However, development stalled and when Rails when to version 2, the gem was no longer compatible.  Fortunately, in mid-2008 rubyforge user “ckiernan” patched the gem and converted it into plugin, making it compatible with Rails 2.  The patch was never committed to the main repository, so the plugin was solely available on this rubyforge tracker page.

However, the plugin again became useless with the release of Rails 2.2.  The call to “require_mysql” was bombing as that method was apparently removed in Rails 2.2.  And so I fixed that and put it on github for all of the Rails world to enjoy.  “Git” it here:

http://github.com/findchris/mysql_replication_adapter/tree/master

Hope someone benefits from this.

Facebook monetization: Dare I suggest the freemium model?

Even your Mom is on Facebook.

Even your Mom is on Facebook.

Everyone and their Mom is on Facebook.  Literally.  I know that my Mom certainly is.  The point is Facebook is growing faster than MySpace and soon all 6,883,817,696 of us will be SuperPoking each other (let’s hope not).  You get the point.

That viral growth of Facebook is what every company would want.  But it seem that Zuckerberg’s platform is quite expensive to operate, and that attempts at deriving value from that huge (and growing) user base haven’t realized the immense potential of such a intricate ecosystem.  So what’s a Web 2.0 darling to do?

You’ve heard of the term “Freemium” right?  It is “a business model which works by offering basic services for free, while charging a premium for advanced or special features.”  Facebook is currently free, so who would pay for its use?  Not me.

Then who will pay to use Facebook?  Businesses.  This is not a new idea.  Most of the product offerings from 37signals offer a basic plan that would only be useful to individuals, charging a recurring fee for more advanced features that businesses can leverage.

Why would businesses pay?  Because:  Businesses cannot afford to abstain from social media participation.  Witness this snippet from ReadWriteWeb article:

“For any company that thought social media was a passing fad not worthy of their time, the numbers coming out of a recent study published by Opinion Research Corporation for Cone should come as a wake-up call. According to that study, 85% of Americans using social media think companies should have an active presence in the social media environment. What’s even more interesting is that those users actually want the companies to interact with them while there.”

Dear businesses, are you getting the message?  Dive into social media:  Consumers want you there!

Does your business belong here?

Does your business belong here?

What does this mean and how would businesses benefit?  In channels like Facebook and Twitter, countless conversations are constantly taking place.  Some of these conversations might involve a product that your company provides.  Why would you not want to be a part of this conversation?  There are some great companies that have already joined the conversation on Twitter, but the same cannot be said for Facebook.  I’d argue that this deficiency is due to a lack of business tools provided by Facebook.

So here’s my proposal:  Charge businesses for premium Facebook profiles.  Allow an unlimited number of “friends”, or perhaps charge based on “friend cap” that would be in accordance with the company’s desired reach (a Mom and Pop taco stand in San Diego doesn’t need to reach consumers the same way Pepsi does).  Facebook should then provide tools to make their presence valuable.  Examples include surveys/voting (read:  new ad campaign testing?), games (read:  engagement widgets), conversations (read:  user feedback and message dissemination), sharing of virtual products, and whatever else might evolve from there.

Some might argue that Facebook is for friends and family only, and that brands have no place in such a space.  To negate that argument, just remember that we are not talking about MySpace and its associated intrusiveness:  You and a business will only have a conversation if it is mutually-consented.  And that is the beauty of the opt-in nature of social media.

What do you think?  Would such a model work for Facebook?  If you have a business, would you use something like the tools outlined in this post?

As a dessert, here is another quality production from Common Craft:

Cough cough. I’m sick of gurus.

The benevolent Guru.

The benevolent Guru.

With the exciting democratization of media, anyone who wants it has a pulpit from which to critique, analyze, rant, and promote.  This is a beautiful thing, because the cream does tend to float to the top.  Numerous individuals producing quality content have gained rightful recognition for the value they provide.  But this media access tide has lifted all boats, greatly increasing the noise surrounding valuable signals.  And there is one member of this new media community that lurks in the dark corners of every channel, hanging out with retired infomercial hosts and sleight-of-hang magicians.

I refer to “gurus“; not in the personal religious teacher sense of the word, but in the “recognized leader in a field” sense.  You would think field leaders would be well-known, widely recognized, and a rare occurrence indeed.  But search Google or twitter and lo and behold:  gurus seem to be a dime a dozen.  How could this be?  How could so many experts exist in every field imaginable?  My guess (as well as yours, I hope) is that many of these “leaders” are trying to misrepresent themselves as “leaders” in the hope of it becoming a self-fulfilling prophecy.  Maybe they’ve watched “The Secret” too many times.  Who knows…

Trust me:  I'm a Guru.

Trust me: I'm a Guru.

Anyway, this post had to be written as a kind of rant.  I love twitter, and it is always interesting to see what type of people you get as followers.  Maybe someone retweeted me, or found one of my tweets through twitter search, or perhaps I am the subject of a marketer trying to gain as many followers as possible:  It happens.  It is this latter class of twitter users that tend to be self-identified as gurus.  Now, I don’t blame these people for trying to hustle (right @garyvee?).  However, there is a right way and wrong way to hustle.  For all of the WineLibrary TV and Gary Vaynerchuk fans out there, you know that Gary knows wine and is passionate about sharing his analysis and insights on the topic.  Maybe you consider him a “guru”, or maybe you reserve that title for someone like Robert Parker.  Either way, he brings real value (through quality content) to the wine world.  He has become a prominent figure because of his quality content, plain and simple; not the other way around.  Had Gary started out claiming to be a “wine guru” without the quality content to back it up, he would be written off by level-headed people as irrelevant.  Instead, he has built a reputation on a solid foundation, just as one would construct any physical building.  Conversely, most “guru”-types try to build a skyscraper without any planning or foundation.

So how do you know if you’ve encountered a guru?  Here are a few indicators:

  • When someone tells you that they are a guru.  As an example, here is one twitter user’s profile description:  “Marketing guru turned social media expert”.  Really?!?
  • When you are offered executive level income within 30 days with little to no effort.  Example:  http://www.top-biz-reviews.com/
  • When you come across an ebook or “program” that will help you become a guru too (making load of money [using new technology] in the process).
  • When you get an unsolicited offer to help you become successful, just like he/she did.

So, I am alone in my sentiment towards these “experts”?  Definitely not.  Here is a funny tweet from @onehipmama:  “Whatever would I do without the “Social Media Gurus” lecturing on how to use Twitter so that I can properly Retweet them?(Eye roll, yawn).”

So why dedicate a blog post to this topic?  Well, simply to express what many others probably feel.  I am sure many of the gurus are great people, I am just not a fan of misrepresentation for exploitation (something that is easier than ever to do).

My advice to this insidious crew:  Create quality content, and the reputation will follow.  But then again, I am no guru ;-)

UPDATE (October 2, 2009): My coworker Adam just sent this video to me, and it resonates so strongly with this post that I had to update it. Enjoy.

Dear Mr Obama - A short letter on the bailouts

Below is a short, cursory letter than probably won’t be read by anyone with power, but hopefully I am wrong.  So I woke up on the cynical side of the bed this morning…

Anyway, taking advantage of the new Change.govShare Your Vision” feature, I decided first thing this morning to fill out the form.  I’ve submitted another “vision” previously, more focused on ecology and environmental balance.  Even if the data from this form is aggregated by a Bayesian filter for easier digestion, I would be quite content (although I would love better tools for facilitating bidirectional communication with the government). I hope soon to write a few posts clarifying my viewpoints, hopefully providing insight and value in the process.

What I wrote:

Dear Mr Obama,

I voted for your.  I donated to your campaign.  And I am an ardent supporter.  I could not hold back tears of joy on election day.

I beg you, however, not to make the mistake of bailing out those who do not deserve to be bailed out.  The American auto industry has failed.  During the highest selling point for cars ever (2 years ago), GM was still not profitable.  Why would you want to support a failure?  It encourages inefficiency, and discourages innovation.  Same goes for banks and bad mortgages.  I live in Los Angeles, and despite the fact that my wife and I could have legitimately afforded a home, we opted not to buy a house during the madness, knowing it was a bubble.  So now I hear talk of bailing out dumb consumers; please prove me wrong.  Please do not reward irresponsible consumers and punish considerate ones by disincentivizing responsible finance.

I feeling helpless with all of these bailouts going on.  I didn’t vote for a bailout, and I know all of my friends and family are against it as well.  This government is all about re-empowering democracy, so why do we all feel so helpless with regard to this bailout?

This recession is a market correction that is needed, and not something that should be avoided and preempted by the government.

Thank you,
Chris Johnson

What are your thoughts regarding the bailouts?