Undefined method `extend' for class `ActiveRecord::Associations::CollectionProxy'

I have a rails 3.2.21 app hosted on Heroku, using Heroku Postgres. I got
the “undefined method extend' for classActiveRecord::Associations::CollectionProxy’” error fired from every
page
on one of the web dynos. After a while the dyno was restarted and
everything went back to normal.

I have no idea what could cause such an error, any hint would be great.

In case you need, here is a stack trace from one of the pages:

….21/lib/active_record/associations/
collection_proxy.rb: 37:in <class:CollectionProxy>' ….21/lib/active_record/associations/ collection_proxy.rb: 36:inmodule:Associations
….21/lib/active_record/associations/
collection_proxy.rb: 2:in <module:ActiveRecord>' ….21/lib/active_record/associations/ collection_proxy.rb: 1:in<top (required)>’
…b/active_record/associations/
collection_association.rb: 25:in initialize' …ve_record/associations/ has_many_through_association.rb: 10:ininitialize’
…/activerecord-3.2.21/lib/active_record/
associations.rb: 160:in new' …/activerecord-3.2.21/lib/active_record/ associations.rb: 160:inassociation’
…ib/active_record/associations/preloader/
association.rb: 18:in run' …ord-3.2.21/lib/active_record/associations/ preloader.rb: 132:inblock (2 levels) in preload_one’
…ord-3.2.21/lib/active_record/associations/
preloader.rb: 131:in each' …ord-3.2.21/lib/active_record/associations/ preloader.rb: 131:inblock in preload_one’
…ord-3.2.21/lib/active_record/associations/
preloader.rb: 130:in each' …ord-3.2.21/lib/active_record/associations/ preloader.rb: 130:inpreload_one’
…ord-3.2.21/lib/active_record/associations/
preloader.rb: 109:in preload' …/squeel/adapters/active_record/ preloader_extensions.rb: 14:inblock in run_with_squeel’
…/squeel/adapters/active_record/
preloader_extensions.rb: 14:in each' …/squeel/adapters/active_record/ preloader_extensions.rb: 14:inrun_with_squeel’
…gems/activerecord-3.2.21/lib/active_record/
relation.rb: 181:in block in exec_queries' …gems/activerecord-3.2.21/lib/active_record/ relation.rb: 180:ineach’
…gems/activerecord-3.2.21/lib/active_record/
relation.rb: 180:in exec_queries' …gems/activerecord-3.2.21/lib/active_record/ relation.rb: 160:inblock in to_a’
…/gems/activerecord-3.2.21/lib/active_record/
explain.rb: 41:in logging_query_plan' …gems/activerecord-3.2.21/lib/active_record/ relation.rb: 159:into_a’
…rd-3.2.21/lib/active_record/relation/
finder_methods.rb: 381:in find_first' …rd-3.2.21/lib/active_record/relation/ finder_methods.rb: 122:infirst’
….1.0/gems/friendly_id-4.0.9/lib/friendly_id/
history.rb: 92:in find_one' …rd-3.2.21/lib/active_record/relation/ finder_methods.rb: 315:infind_with_ids’
…rd-3.2.21/lib/active_record/relation/
finder_methods.rb: 107:in find' /app/app/controllers/ programs_controller.rb: 8:inshow’
…-3.2.21/lib/action_controller/metal/
implicit_render.rb: 4:in send_action' …gems/actionpack-3.2.21/lib/abstract_controller/ base.rb: 167:inprocess_action’
…onpack-3.2.21/lib/action_controller/metal/
rendering.rb: 10:in process_action' …actionpack-3.2.21/lib/abstract_controller/ callbacks.rb: 18:inblock in process_action’
…s/activesupport-3.2.21/lib/active_support/
callbacks.rb: 458:in _run__283287050225388972__process_action__1943163135672811662__callbacks' …s/activesupport-3.2.21/lib/active_support/ callbacks.rb: 405:in__run_callback’
…s/activesupport-3.2.21/lib/active_support/
callbacks.rb: 385:in _run_process_action_callbacks' …s/activesupport-3.2.21/lib/active_support/ callbacks.rb: 81:inrun_callbacks’
…actionpack-3.2.21/lib/abstract_controller/
callbacks.rb: 17:in process_action' …ctionpack-3.2.21/lib/action_controller/metal/ rescue.rb: 29:inprocess_action’
…-3.2.21/lib/action_controller/metal/
instrumentation.rb: 30:in block in process_action' …tivesupport-3.2.21/lib/active_support/ notifications.rb: 123:inblock in instrument’
….2.21/lib/active_support/notifications/
instrumenter.rb: 20:in instrument' …tivesupport-3.2.21/lib/active_support/ notifications.rb: 123:ininstrument’
…-3.2.21/lib/action_controller/metal/
instrumentation.rb: 29:in process_action' …k-3.2.21/lib/action_controller/metal/ params_wrapper.rb: 207:inprocess_action’
….2.21/lib/active_record/railties/
controller_runtime.rb: 18:in process_action' …gems/actionpack-3.2.21/lib/abstract_controller/ base.rb: 121:inprocess’
…actionpack-3.2.21/lib/abstract_controller/
rendering.rb: 45:in process' …/gems/actionpack-3.2.21/lib/action_controller/ metal.rb: 203:indispatch’
…-3.2.21/lib/action_controller/metal/
rack_delegation.rb: 14:in dispatch' …/gems/actionpack-3.2.21/lib/action_controller/ metal.rb: 246:inblock in action’
…onpack-3.2.21/lib/action_dispatch/routing/
route_set.rb: 73:in call' …onpack-3.2.21/lib/action_dispatch/routing/ route_set.rb: 73:indispatch’
…onpack-3.2.21/lib/action_dispatch/routing/
route_set.rb: 36:in call' …le/ruby/2.1.0/gems/journey-1.0.4/lib/journey/ router.rb: 68:inblock in call’
…le/ruby/2.1.0/gems/journey-1.0.4/lib/journey/
router.rb: 56:in each' …le/ruby/2.1.0/gems/journey-1.0.4/lib/journey/ router.rb: 56:incall’
…onpack-3.2.21/lib/action_dispatch/routing/
route_set.rb: 608:in call' …uby/2.1.0/gems/omniauth-1.0.3/lib/omniauth/ strategy.rb: 168:incall!’
…uby/2.1.0/gems/omniauth-1.0.3/lib/omniauth/
strategy.rb: 148:in call' …uby/2.1.0/gems/omniauth-1.0.3/lib/omniauth/ strategy.rb: 168:incall!’
…uby/2.1.0/gems/omniauth-1.0.3/lib/omniauth/
strategy.rb: 148:in call' …ruby/2.1.0/gems/omniauth-1.0.3/lib/omniauth/ builder.rb: 42:incall’
…dle/ruby/2.1.0/gems/sass-3.2.9/lib/sass/plugin/
rack.rb: 54:in call' …by/2.1.0/gems/rack-cache-1.2/lib/rack/cache/ context.rb: 136:inforward’
…by/2.1.0/gems/rack-cache-1.2/lib/rack/cache/
context.rb: 245:in fetch' …by/2.1.0/gems/rack-cache-1.2/lib/rack/cache/ context.rb: 185:inlookup’
…by/2.1.0/gems/rack-cache-1.2/lib/rack/cache/
context.rb: 66:in call!' …by/2.1.0/gems/rack-cache-1.2/lib/rack/cache/ context.rb: 51:incall’
…dle/ruby/2.1.0/gems/warden-1.1.1/lib/warden/
manager.rb: 35:in block in call' …dle/ruby/2.1.0/gems/warden-1.1.1/lib/warden/ manager.rb: 34:incatch’
…dle/ruby/2.1.0/gems/warden-1.1.1/lib/warden/
manager.rb: 34:in call' …b/action_dispatch/middleware/ best_standards_support.rb: 17:incall’
…dor/bundle/ruby/2.1.0/gems/rack-1.4.5/lib/rack/
etag.rb: 23:in call' …/ruby/2.1.0/gems/rack-1.4.5/lib/rack/ conditionalget.rb: 25:incall’
…tionpack-3.2.21/lib/action_dispatch/middleware/
head.rb: 14:in call' …3.2.21/lib/action_dispatch/middleware/ params_parser.rb: 21:incall’
…ionpack-3.2.21/lib/action_dispatch/middleware/
flash.rb: 242:in call' …/2.1.0/gems/rack-1.4.5/lib/rack/session/abstract/ id.rb: 210:incontext’
…/2.1.0/gems/rack-1.4.5/lib/rack/session/abstract/
id.rb: 205:in call' …npack-3.2.21/lib/action_dispatch/middleware/ cookies.rb: 341:incall’
…s/activerecord-3.2.21/lib/active_record/
query_cache.rb: 64:in call' …record/connection_adapters/abstract/ connection_pool.rb: 479:incall’
…ack-3.2.21/lib/action_dispatch/middleware/
callbacks.rb: 28:in block in call' …s/activesupport-3.2.21/lib/active_support/ callbacks.rb: 405:in
_run__2305709260636702136__call__3264484816793770857__callbacks’
…s/activesupport-3.2.21/lib/active_support/
callbacks.rb: 405:in __run_callback' …s/activesupport-3.2.21/lib/active_support/ callbacks.rb: 385:in_run_call_callbacks’
…s/activesupport-3.2.21/lib/active_support/
callbacks.rb: 81:in run_callbacks' …ack-3.2.21/lib/action_dispatch/middleware/ callbacks.rb: 27:incall’
…ack-3.2.21/lib/action_dispatch/middleware/
remote_ip.rb: 31:in call' …0/gems/airbrake-4.1.0/lib/airbrake/rails/ middleware.rb: 13:incall’
….21/lib/action_dispatch/middleware/
debug_exceptions.rb: 16:in call' …2.21/lib/action_dispatch/middleware/ show_exceptions.rb: 56:incall’
…by/2.1.0/gems/railties-3.2.21/lib/rails/rack/
logger.rb: 32:in call_app' …by/2.1.0/gems/railties-3.2.21/lib/rails/rack/ logger.rb: 16:inblock in call’
…ivesupport-3.2.21/lib/active_support/
tagged_logging.rb: 22:in tagged' …by/2.1.0/gems/railties-3.2.21/lib/rails/rack/ logger.rb: 16:incall’

We also get these errors on heroku from time to time. I wish I knew what
was causing them. A restart always solves the problem.

N.