Posts Tagged ‘rails’

Xapian search – acts_as_xapian tip (II)

Saturday, September 20th, 2008

Further to my first post on using acts_as_xapian, I have been trying to make xapian work with pagination and association proxies properly

class Lesson < ActiveRecord::Base
# Index user_id as a term in xapian

    belongs_to :user
    def self.find_with_xapian(search_term, options={})
      ActsAsXapian::Search.new([self], search_term, options).results.collect{|x| x[:model]}
    end
end

class User < ActiveRecord::Base
    has_many :lessons do  #Extend this association
      # Override the method in lessons
      def self.find_with_xapian(search_term, options={})
        ActsAsXapian::Search.new([proxy_reflection.klass],
          "{proxy_reflection.primary_key_name}:#{proxy_owner.id}  #{search_term}", options)
        .results.collect{|x| x[:model]}
      end
    end
end

This will ensure that current_user.locations.find_with_xapian will find the correct number of locations, enabling us to work with pagination, etc. What’s left to do is to get the Search object out so that we can get matches_estimated out. I’ll leave out for next time.

This post was brought to you from Software Freedom Day, New Zealand.

Rails 2.0.2 – test setup not being called

Monday, April 21st, 2008

The setup method for ActionController::TestCase is useful in some circumstances, e.g. having a user login in your tests.

def setup
super
login_as :quentin
end

However, when you run the tests, all your tests with login_required fails.

Basically, this is a bug in Rails 2.0.2 where setup is not called. This was fixed in revision 8442 (one revision after rails 2.0.2 was released). See http://dev.rubyonrails.org/ticket/10568

So, we would want that revision by using:

rake rails:freeze:edge REVISION=8442

NOTE: rubyonrails.org is down/domain expired so rake might fail. In the meantime, try svn export or some other way to get revision 8442 from another repository.

UPDATE: rubyonrails.org is back up (domain renewed)!


http://www.canakkaleruhu.org http://www.vergimevzuati.org http://www.finansaldenetci.com http://www.securityweb.org http://www.siyamiozkan.org http://www.fatmaozkan.com http://www.sgk.biz.tr http://www.denetci.gen.tr http://www.bagimsizdenetim.biz.tr http://www.mevzuat.biz.tr http://www.security.biz.tr http://www.sorgulatr.com http://www.kanunlar.biz http://www.prsorgu.net http://www.sirabul.com http://www.emekliol.org http://www.coklupagerank.com http://www.coklupagerank.net http://www.coklupagerank.org http://www.prsorgu.org http://www.scriptencode.com http://www.sirabul.net http://www.sirabul.org http://www.sitenizanaliz.com http://www.seoisko.com http://www.seomavi.com http://www.scriptencode.net http://www.scriptencode.org