#179 new
Tony

scope call in ClassMethods#find_with_ferret breaks rails 3

Reported by Tony | October 27th, 2010 @ 01:39 PM

I believe the scope method in rails 3 is different than in earlier rails releases

http://github.com/jkraemer/acts_as_ferret/blob/master/lib/acts_as_f...

scope(:find, :conditions) overrides the default find resulting in some strange behavior on rails 3.

def find_with_ferret(q, options = {}, find_options = {})
  if respond_to?(:scope) && scope(:find, :conditions)
    find_options[:conditions] ||= '1=1' 
  end
  return ActsAsFerret::find q, self, options, find_options
end

I'm not sure what this did in Rails 2 but skipping that block if Rails::VERSION::STRING.start_with?("3") seems to work for me.

def find_with_ferret(q, options = {}, find_options = {})
  unless Rails::VERSION::STRING.start_with?("3")
    if respond_to?(:scope) && scope(:find, :conditions)
      find_options[:conditions] ||= '1=1' # treat external scope the same as if :conditions present (i.e. when it comes to counting results)
    end
  end
  return ActsAsFerret::find q, self, options, find_options
end

I'm also running changes specified in tickets 176 and 177

Comments and changes to this ticket

  • Tony

    Tony October 27th, 2010 @ 01:48 PM

    I guess the Rails::VERSION::STRING.start_with?("3") check isn't needed as the documentation mentions that 0.5 is rails 3 only.

    I think we just kill the block then but I suspect this was something we needed

    treat external scope the same as if :conditions present (i.e. when it comes to counting results)

    def find_with_ferret(q, options = {}, find_options = {})
    return ActsAsFerret::find q, self, options, find_options end

  • Tony

    Tony November 8th, 2010 @ 04:45 PM

    FYI. my changes for 176, 177 and 179 are here

    https://github.com/primerano/acts_as_ferret

    Add this to Gemfile if you want to use them

    gem 'acts_as_ferret', '= 0.5.2', :git => "git://github.com/primerano/acts_as_ferret.git

    unfortunately the AAF tests don't seem to work with Rails3 so I didn't submit a pull request as I don't want to break anything.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Shared Ticket Bins

People watching this ticket

Pages