Posts tagged gems

All posts

Seed Dump!

You might remember my rant/advice on keeping your seed.rb file up-to-date.

Well, I’ve found something a very cool gem that might just do the trick when just giving the newbie a dump of the database isn’t possible for any reason: Seed Dump gem by rroblak

This gem will add a rake task that will generate a seed.rb file containing as much actual data from your development database (which is supposed to be consistent with your data model) as you want.

Simpy wonderful!


Multiple Installations Mayhem: MySQL

While trying to build and install PHP 5.4 in a OS X 10.7.5 in order to test Laravel, I found myself updating several things with Homebrew. It seems that one of the things updated was my brew installation of MySQL.

The thing is that later, I tried to boot the Rails console for a project and it puked this fearsome line:

~/.rvm/gems/<gemset>/gems/activesupport-2.3.17/lib/active_support/dependencies.rb:466:in
    `load_missing_constant':NameError: uninitialized constant MysqlCompat::MysqlRes

As delicate as installing MySQL in Mac OS X and getting it to work is, I knew this was a bad omen. Yes. I couldn’t make any query using the rails console.

So, after checking the Internet, the first probable cause is that after changing the MySQL installation you would need to rebuild the mysql gem. So, after checking ‘which MySQL’ was in use, I reinstalled the gem with some options:

env ARCHFLAGS="-arch x86_64" \
gem install mysql -v=2.8.1 --with-mysql-config=/usr/local/mysql/bin/mysql_config

Everything went smoothly, but I had the same error when firing up the console. Damn. The next thing I found about it was about the libmysqlclient not being installed or found. But locate libmysqlclient gave me three different paths… so it had to be about the library not being visible. After researching, the library is usually looked for in the $DYLD_LIBRARY_PATH. Set the proper path in your .bash_profile (something along /user/local/mysql/lib) and you’ll get going.


Simple good practices you’re probably not following: THE RETURN

This one is pretty simple too, and very easy. Specify the version of the gems you are using in the Gemfile. Or in your environment.rb if you are into Rails Archaelogism. Wait, SPECIALLY if you’re dealing (or know that someone will) with old projects.

Let’s say you start developing a project and you want to use a gem.

  gem "capistrano-tasks" # shameless plug LOL

At that time, you’ll probably just go with whichever version rubygems throws at you. That’s ok. But when you deploy into staging for the first time, make sure to note down the version of the gem that’s being used in the staging machine and specify that version in the Gemfile.

    gem "capistrano-tasks", "~> 0.1.0" # shameless plug LOL

You’ll make your life a little easier when going into production for the first time because you’ll be using the same gem version (and dependencies), and A LOT easier for the next guy in line trying to get the project up and running.

Be a good guy and just try to think a little in advance and be nice to the future devs, or your future self. Anyway, it seems that you’re going to need to do this in Rails 4.


Capistrano-Tasks gem released

I’ve put up a teeny little gem which compiles some Capistrano tasks I’ve developed and been using for a while. Just to learn how to compile a gem by myself and also how to create a cookbook.

It’s also the first time I make public some of my code, and well, it’s exciting. Forking, testing, comments, suggestions are of course welcome. I’m willing to listen to everything you might suggest, from changing names of symbols, using other commands, or even changing the license. That’s the point of releasing it into the wild :) Thanks in advance.

You can get the gem at github.com/jantequera/capistrano-tasks. Where else?

I used this article (bit outdated, tho) by Tim Riley and the Webficient Capistrano Cookbook to learn the how-to. The second link provides a gem/cookbook much more suitable for production use, if you’re looking for one. I consider my gem for personal use and learning.