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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment