module Scope
protected
def method_missing(method_id, arguments, &block)
if method_id.id2name =~ /^scope_([_a-z]\w)to([_a-z]\w*)/
scope_model($1.singularize.capitalize, “#{$2}_id”, &block)
else
super
end
end
def scope_model(klass, foreign_key, &block)
eval(klass).with_scope({
:find => { :conditions => [ "#{foreign_key} = ?",
params[foreign_key] ]},
:create => { :user_id => params[foreign_key] }
}, &block)
end
end
Creates methods like ‘scope_products_to_user’,
‘scope_messages_to_mailbox’, etc.
The problem is meantime_filter isn’t running my method_missing method.
meantime_filter :scope_products_to_user #=> NameError: undefined method
scope_products_to_user' for class
ProductsController’
I can only seem to run the methods from the controller.
meantime_filter :scope_products_to_user_temp
def scope_products_to_user_temp
scope_products_to_user { yield }
end
This works fine.
I think the problem is with how meantime_filter runs its methods.
If it’s not fixable, is there any of good ways of achieving the same
effect?