This project is archived and is in readonly mode.

#4372 ✓invalid
Mario

Some plugins overriding method_missing crashes

Reported by Mario | April 12th, 2010 @ 05:41 PM

For example, the plugin searchlogic utilizes method_missing to create new named scopes. When it hits method_missing it creates a named scope (using define_method) to ensure it will never hit method_missing for that named scope again. Sort of a caching mechanism. It works in the same fashion as ActiveRecord’s "find_by_*" methods. This way only the named scopes you need are created and nothing more.

This is awesome, but it implies that in the same application can't be another plugin that overrides method_missing. If two plugins (or custom models) overrides method_missing (even if they use super) only the last override is valid. Moreover most times is necessary to reimplement the respons_to method too.

There will be a mechanism like a chain or something else to prevent this behavior...

ActiveRecord should have a hook in its method_missing implementation, chainable (for use in plugins), that can be defined more than one time; something like on_method_missing do |method_missing_name| ... end declaration to use in models could be nice.

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 »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages