Archive for March, 2011

Reloading Rails console without exiting

by Ali. 0 Comments

In my journey to hopefully master Ruby on Rails, I’m amazed to see that many authors (in blogs or in books) most of whom are pretty expert in the field, choose to exit the Rails console completely (using CTRL+D) when they need to restart the environment (to clear up the objects in the memory, for example).

Instead there is a convenient method:

reload!

that you can type inside Rails console and it will reload the environment for you. No need to wait extra second to exit and reenter the console.

P.S. There might be a wisdom in not choosing realod! which I might not be aware of. In that case please enlighten me in the comments.

government,politics news,politics news,politics

Running MySQL 5.5 and Rails 3 on Mac OS X

by Ali. 15 Comments

A recent opportunity made me dust off my development skills and I decided to use Ruby on Rails as the framework of choice.

I’m happy with Ruby 1.8.7 for now (comes with Mac OS X Snow Leopard), but I had to update Rails to version 3, which was a painless process. After installing MySQL 5.5.10 (dumping MAMP for now), I installed the ruby gem for MySQL:

$ sudo gem install mysql2

You may want to run this too, although the first one should do the trick:

$ sudo gem install mysql

A quick test got me this piece of error:

LoadError: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
Reason: image not found – /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require’
from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2.rb:7
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require’
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require’
from (irb):1

You can never have a perfect installation experience. Can you?

A thread on Stack Overflow guided me to this solution:

$ sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql-5.5.10-osx10.6-x86_64/lib/libmysqlclient.18.dylib /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle

Note: As it happened with me, you might have the same problem that MySQL failed to create a link (alias) in the /usr/bin folder. You can fix it with a quick ln command:

$ sudo ln /usr/local/mysql-5.5.10-osx10.6-x86_64/bin/mysql /usr/bin/mysql

PS: This solution is based on the latest versions of the libraries available as of March 2011. You might need to change the versions in the commands or paths according to your machine settings.

government,politics news,politics news,politics