Feb 3

I’ve been running with the Rails MySQL adapter for a while now after failing to build the native MySQL gem under Leopard. The problem, I thought, was that I’m using the Macports MySQL, and it turns out I was right. If you attempt to build the MySQL gem and you get an error like this:

Building native extensions.  This could take a while...
ERROR:  While executing gem ...
(Gem::Installer::ExtensionBuildError)
    ERROR: Failed to build gem native extension.

ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no

Gem files will remain installed in
/opt/local/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

Then you’ll need to add a couple of things to your Gem command line to get it building:

If you’re just installing or updating the gem, try this:

sudo gem install mysql -- --with-mysql=/opt/local/lib/mysql5 --with-mysql-lib=/opt/local/lib/mysql5/mysql --with-mysql-include=/opt/local/include/mysql5/mysql

If you’re updating all your gems (this one caught me out), then try this:

sudo gem update -- --with-mysql=/opt/local/lib/mysql5 --with-mysql-lib=/opt/local/lib/mysql5/mysql --with-mysql-include=/opt/local/include/mysql5/mysql
Sep 20

Dates and times in fixtures

Posted by Cliff

Just a micro tip. If you’re inserting dates and/or times into your database via fixtures whether for testing or to load initial data, it’s not enough just to specify the date. This won’t work:

some_fixture:
  id: 1
  created_at: <%= 2.days.ago %>

You need to coorce the data into the appropriate format like so:

some_fixture:
  id: 1
  created_at: <%= 2.days.ago.to_s :db %>