Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Is that possible to define named scope in a module?

Say there are 3 models: A, B, and C. Each of these models has the x attribute.

Is that possible to define a named scope in a module and include this module in A, B, and C ?

I tried to do so and got an error message saying that scope is not recognized...

like image 800
Misha Moroshko Avatar asked Jan 15 '11 11:01

Misha Moroshko


1 Answers

Yes it is

module Foo   def self.included(base)     base.class_eval do       scope :your_scope, lambda {}     end   end end 
like image 103
Omar Qureshi Avatar answered Sep 19 '22 21:09

Omar Qureshi