Receive updates via email:

 Updates via RSS

Tag Cloud

Blog Archive

Tuesday, December 09, 2008

Ruby on Rails, Facebook, Invalid char `\222' in expression

It had been a really long time since I have done any *real* coding. A really long time -- almost 8 years since I had written any hard core code. Thinking a little more about it, I should probably back a little away from that statement -- as system administrators and DBA would probably take exception to it. I had written a lot of PERL and AWK scripts, numerous database scripts, stored procedures and packages from Oracle, but not any "application" related code.

Why start now?

I had *read* somewhere that creating a Facebook application was really easy to create. That's actually a joke and a serious over-exaggeration, but I had some pretty cool ideas for Facebook applications that did not exist. Plus, I was interested in learning more about some technologies like Ruby / Ruby on Rails, so that was seemingly a perfect fit -- an idea combined with the need to update myself on some development technologies.

So I took the dive. Literally.

I really had *heard* that it was fairly simple to create new Facebook application. But I was not naive enough to think that I could really develop something of any value in 30 minutes. I really did not have a clue how long it would take, but was hoping it was something I could put together from scratch in about 2 weeks. We'll see how that goes.

And, in retrospect -- I started the process a little backwards. What did I do?

I was going to create a Facebook application, right? So that meant that I immediately headed over to the Facebook Developers' site, signed up and registered my application.

Then I headed over to the "recommended" hosting provider for Ruby on Rails applications, Joyent to sign up for the free Facebook development hosting that they offer. Now I was ready to build and deploy my application, right?

One problem -- I had no idea what Ruby was or the difference between Ruby, JRuby or Ruby on Rails. It was time to figure that out. So, I headed over to the Ruby on Rails website, downloaded Ruby on Rails and started working my way through the Getting Started with Rails Guide.

To some extent, I raised my nose towards the guide that suggested the best experience was on non-Windows operating systems. Not because I did not have a Linux Virtual Machine available, but simply because it was a little more portable between my home server (Windows Server 2008), my home Desktop (Windows Vista Ultimate) and my work laptop (Windows XP). I proceeded down the installation path.

First I installed Ruby Language -- version 1.8.6, release 26. No issues there.

Then I installed the RubyGems Packaging system. No issues there.

Then I installed MySQL 64-bit (x64). And that's where the problem began.

Because I am running the 64-bit version of the Windows Server 2008 operating system, it made sense to me to install the 64-bit version of MySQL. I downloaded it and proceed with the installation of both the Server and the MySQL Administrator. I verified that I had database connectivity.

I then proceeded with the Ruby on Rails getting started guide.

I installed rails.

Then I tried to start interacting with the MySQL database, starting the Web Server and then getting the Application Home Page setup properly. Finally, when I was ready to access the blogs application, I hit an error message.

libmysql.dll was not found ruby.exe

And I could not figure it out. One Google post recommended copying the libmysql.dll from the MySQL bin location to the Ruby bin location, but that did not solve my problem. Then I saw a note about reinstalling the MySQL connectivity in Ruby / Rails. When viewing the MySQL gems installation package I recognized that "32" for 32-bit (x86) was in the file name.

That made it click. I had installed the 64-bit version of MySQL, but Ruby's support for MySQL was only with a 32-bit driver. Ugh. Would have been nice to reference that in the getting started guide, but I persevered.

I uninstalled the 64-bit version of MySQL, rebooted, downloaded, and installed the 32-bit version of MySQL. Great news, I was able to establish connectivity to the Ruby on Rails Blog sample site.

Now it was time to shift my attention a little, back to the application development. I had established that I could deploy / run an already created Ruby on Rails application -- now I needed to build one.

To start, I realized that I needed to thing about the application that I wanted to build in 4 stages. They were:

1. Acquire the data I was interested in.
2. Parse and save that data to a database (MySQL)
3. Display that data within an application. (Ruby on Rails)
4. Integrate that application with Facebook.

Easy enough, right?

So, I set off on a two hour (don't laugh) journey to *learn* Ruby and build a script that could display the data I was interested in. After a couple of hours and trying several GEM packages (which I'll discuss in a later article), I hit a wall.

No matter what the script was, or the sample code I used, I kept getting the same error:
Invalid char `\222' in expression

I tried a number of fixes and searched Google, but I could not get the Ruby scripts to run properly. After about 30 minutes of this, I decided to put it down for the evening.

However, tonight -- I was able to get some basic scripts to run. What did I do to fix the "Invalid char `\222' in expression" error? In Windows Server 2008, I change the single quotes in the sample script code I was using to double quotes.

Could it really be that simple?

The jury is out on that -- now that I have the code running correctly 24-hours later, if I change the double quotes back to single quotes -- I cannot reproduce the error. That being said, I am glad the error is gone. :-) Has anyone else encountered the Invalid char errors?

That's it for now for the Facebook application development using Ruby on Rails. I'll update soon on how step 1 is coming along.


Johan said...

The invalid char error was due to a "windows" quote instead of a normal single quote... finally, you should have run Linux and save a day ;)