Look ma, no hands!
15
Feb 11
uninitialized constant MysqlCompat::MysqlRes…getting Snow Leopard, Rails, and MySQL to play nicely
You’ve probably done it…set up your machine, updated Rails, installed MySQL, then attempted to start your server. You’re cruising…then blam!
Then you’ve probably hit Google a few times…tried specifying x86_64 ARCHFLAGS, installing and reinstalling MySQL and the MySQL gem, and even trying the MySQL 2.7 gem.
No dice. You and I both.
Well, hear this…you might have another out! A few weeks ago I was working with the guys over at Blue Box Group to get a Memcached instance up. They had suggested I install Homebrew, a package manager for OS X. I suggest you install it too.
Be sure to uninstall the any copies of your mysql gem; then, once you have it Homebrew running, try the following.
==> Downloading ftp://ftp.cwru.edu/pub/bash/readline-6.1.tar.gz
################################################## 100.0%
==> Downloading patches
################################################## 100.0%
** snip **
icarus$ sudo gem install mysql -- --with-mysql-dir=/usr/local --with-mysql-config=/usr/local/bin/mysql_config
Supplies!
19
Jan 11
Using regular expressions? The Devil is in the details.
Recently, I ran into a little roadblock as I’ve been cleaning up some bugs for one of my applications. I rely heavily on cross pollination of data between sites to drive traffic across my network. In this particular situation, a simple collection of linked image thumbnails accomplishes this task.
One of the helper methods that I use returns the file name of a supplied post object. To do this, I perform a regular expression match against the post’s URL and return the result.
# returns "icon/foo.jpg"
def filename_from_post(post)
return post.image.url(:icon).match(/icon\/.*\.jpg)/)[0]
end
That worked great until my application would randomly throw a NoMethodError. I spent a while scratching my head, looking over my code, checking my SQL queries, and so on and so forth. Finally, I figured it out…I had forgotten to specify a case insensitive search!
# returns nil
>> post.url(:icon).match(/icon\/.*\.jpg/)
=> nil
>> post.url(:icon).match(/icon\/.*\.jpg/i)
=> #<MatchData "icon/bar.JPG">
I guess what they say is true…the Devil is in the details.
















