Question

I'm upgrading from Rails 2.3.5 to 2.3.17 and have come across a pretty obscure problem. I use the following extensions to inject a scope within an association accessor, and provider a custom builder:

module XYZFilterExtension

  def in_context(context)
    if proxy_owner.context == :abc && context != :admin
      scoped(:conditions => {:startup => false})
    else
      scoped({})
    end
  end

end

module OtherExtension
  def build_with_component_instance(attributes = nil)
    attributes ||= {}
    attributes.reverse_merge!(:parent_id => proxy_owner.component_instance.id)

    instance = build
    instance.build_component_instance
    instance.attributes = attributes

    instance
  end
end

has_many :pages, :extend => [ABCExtension, OtherExtension]

In Rails 2.3.5 I could call:

Something.pages.in_context(:abc).build_with_component_instance

and I'd get a Page object (And it's associated component_instance, the build is complicated because it's a polymorphic association being built from the other direction).

Now I get:

undefined method `build_with_component_instance' for #<Class:0x1151dcae8>

Inspecting the scope, the only difference that I could find is that calling proxy_scope on the scope created by in_context() returns the Page model in 2.3.17 and the scope in 2.3.5.

I'm not sure where to go from here. I can't extract the scope out into a module to include in each model because I need to make a decision based on the proxy_owner in the association.

Update: It appears the problem is around extension methods not being available within the context of a scope. Pretty strange but I guess it kind of makes sense. Unfortunately both my scope definition and the build extension require knowledge of their association context. Any ideas welcome :)

Was it helpful?

Solution

I ended up not finding a way to work around this. In the end I had to avoid the bug in the specific situation in which it occurred. Fortunately it was only in a couple of places in the app.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top