This project is archived and is in readonly mode.

#3766 open
Stephan Kaag

On-the-fly created named-scope raises 'undefined method `call' when called from subclass with cache_classes = true

Reported by Stephan Kaag | January 21st, 2010 @ 04:42 PM | in 2.3.10

Summary:

I create a named_scope at runtime (a pattern that searchlogic (http://github.com/binarylogic/searchlogic) also relies on). When the named-scope is first called on the super class an error is raised when I call that same scope in the subclass. I am not familiar enough with the codebase to provide a solution myself.

This error occurs in both Rails 2.3.5 and 3.0pre.

To reproduce:

Rails3::Application.configure do
  config.cache_classes = true
end

class Candidate < ActiveRecord::Base
  def self.create_second_order_scope
    return if respond_to?(:second_order)
    named_scope :second_order, :conditions => {}
  end
end

class Admin::Candidate < Candidate
end

Error trigger:

Candidate.create_second_order_scope
Candidate.second_order
Admin::Candidate.create_second_order_scope
Admin::Candidate.second_order
>> undefined method `call' for nil:NilClass

Comments and changes to this ticket

Create your profile

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

Tickets have moved to Github

The new ticket tracker is available at https://github.com/rails/rails/issues

Shared Ticket Bins

Attachments

Pages