Friday, December 28, 2007

Temporarily Turning Off Acts_As_Solr

In a current project, I need to run a rake task that populates a Person table with data from Active Directory. The Person table uses acts_as_solr.

The problem is that the Net:LDAP gem and acts_as_solr seem to conflict with each other. When I define acts_as_solr in the Person table, I get a bind error in Net:LDAP. I have tried changing port numbers for acts_as_solr, but no go.

So, here's a work around that might be helpful to others. What I want is the ability to temporarily turn off acts_as_solr in the Person model, run the rake task to populate the table, then turn acts_as_solr back on.

First, in the Person model here is how include acts_as_solr:

acts_as_solr if AppConfig.solr_on

So, acts_as_solr will only be included if a global variable called solr_on is true.

Now, in the rake task, I first set solr_on to false:

AppConfig.solr_on = false

Then, I re-load the Person class, so that acts_as_solr will not be included:

load "#{RAILS_ROOT}/app/models/person.rb"

Finally, at the bottom of the rake task, I set solr_on back to true and re-load the Person class, so that acts_as_solr will be included. I also reindex solr so that the added records will be included:

AppConfig.solr_on = true
load "#{RAILS_ROOT}/app/models/person.rb"
Person.rebuild_solr_index

This might be beneficial in a more generic context.

Friday, December 21, 2007

Mac Ports upgrade of ruby breaks dbi/odbc

In case anyone else runs into this hair-puller-outer:

I upgraded the Mac Ports version of ruby on my Macbook and suddenly my rake tasks that use dbi/odbc were bombing saying ruby couldn't find the ODBC driver for dbi. I made sure my rb-dbi and rb-odbc were the latest ports, but no go. Finally, I uninstalled rb-odbc and reinstalled rb-odbc, same version, and things started working again. Go figure.