I'm attempting to share a named scope between two models via a module. It is not working for me. I keep getting an undefined error. I'm trying with an empty 'your_scope' scope:
config/initializers/boxshare_init.rb
require 'assets/named_scopes/m.rb'
lib/assets/named_scopes/m.rb
module M
def self.included(base)
base.class_eval do
scope :your_scope, lambda {}
end
end
end
app/models/folder.rb
class Folder < ActiveRecord::Base
include M
acts_as_tree
belongs_to :user
has_many :assets, dependent: :destroy
end
rails console: $ rails c
Loading development environment (Rails 4.1.1) irb: warn: can't alias
context from irb_context.
2.0.0-p0 :001 > Folder.last.your_scope
Folder Load (0.1ms) SELECT "folders".* FROM "folders" ORDER BY "folders"."id" DESC LIMIT 1
NoMethodError: undefined method `your_scope' for <Folder:0x007fd781a1daf0>
Where am I going wrong?