Is Rails clever or smart?

When generating a Rails project you can specify the database adapter. If you select mysql, then Rails 3.0.0 translates mysql to mysql2, which is (or should be) the current adapter for MySQL in Ruby.

I smell a hack here, like a solution belonging elsewhere.

Problem: A new MySQL adapter is available, so how do we make Rails compatible with it?

Clever solution: We translate mysql to mysql2, so that any time a user requests the old mysql adapter, the new mysql2 adapter will be used instead.

Smart solution: We add mysql2 alongside mysql, so that Rails users will decide which adapter they want.

I think that Rails implemented the clever solution because there are Rails developers that write applications in IDEs, which are released infrequently. Those developers would have to wait a lot to get the new mysql2 adapter accessible from their IDEs. So, a transparent translation is very effective in this case, because an IDE dialog for generating a project will execute the “rails new” command under the hood, requesting the mysql adapter. The problem is that there’s no way to use the old mysql adapter, if a Rails developer really wants to, except for hacking Rails itself.

Anyway, I think that Rails could have been smarter. When the user issues the “rails new” command, these are the possible combinations:

  1. mysql2 is installed but mysql is not
    If the user specifies “–database=mysql”, Rails should inform: “using available mysql2 adapter instead of specified mysql”, thus translating mysql to mysql2. This takes care of the fact that mysql2 is meant to replace mysql.
    If the user specifies “–database=mysql2”, Rails should use the specified adapter.
  2. mysql is installed but mysql2 is not
    If the user specifies “–database=mysql”, Rails should use the specified adapter.
    If the user specifies “–database=mysql2”, this should be considered an error and Rails should stop and inform the user. This takes care of the fact that mysql2 has been released after mysql.
  3. neither mysql2 nor mysql are installed
    If the user specifies “–database=mysql” or “–database=mysql2”, this is an error and Rails should stop and inform the user.
  4. both mysql2 and mysql are installed
    If the user specifies “–database=mysql” or “–database=mysql2”, Rails should use the specified adapter.

Browsing Rails code, I see that they were implementing mysql2 alongside mysql, but eventually translated the latter to the former.

NetBeans 6.9.1 + Ruby 1.9.2 + Rails 3.0.0 + Debugging

This fix is for anyone that has NetBeans 6.9.1, Ruby 1.9.2, Rails 3.0.0, already installed, and decides to add support for debugging on Windows XP.

That was my configuration, but it didn’t work properly. A debug session always ended with an error about a non existing script/rails file. After some research, today I discovered this fix that eventually allows me to cleanly debug a Ruby on Rails 3.0.0 project.

ONCE
  1. Download DevKit 4.5.0 from http://rubyinstaller.org/downloads/
  2. Install DevKit as described at http://github.com/oneclick/rubyinstaller/wiki/Development-Kit
  3. Enter the command
  4. Enter the command
  5. Edit the file (Ruby folder)/lib/ruby/gems/1.9.1/gems/ruby-debug-ide19-0.4.12/lib/ruby-debug-ide.rb as follows This one isn’t required, but I find wrong labels very distracting
  6. Edit the file (Ruby folder)/lib/ruby/gems/1.9.1/gems/ruby-debug-ide19-0.4.12/bin/rdebug-ide.rb as follows See also: http://netbeans.org/projects/ruby/lists/users/archive/2010-09/message/25
PER PROJECT
  1. Edit the file (Project folder)/Gemfile as follows
  2. delete the file (Project folder)/Gemfile.lock
  3. Enter the command

That’s all. I hope it’ll work for you too 🙂