我在用着
Ruby version 1.8.7 Rails version 3.0.3
我的rails应用程序的每个模型都有一个叫做alive的方法:
def alive where('deleter is null') end
我不想在每个模型中复制这个代码,所以我做了一个/lib/life_control.rb
module LifeControl def alive where('deleter is null') end def dead where('deleter is not null') end end
在我的模型(例如client.rb)中我写道:
class Client < ActiveRecord::Base include LifeControl end
在我的config / enviroment.rb中我写了这一行:
require 'lib/life_control'
NoMethodError in ClientsController#index undefined method `alive' for #<Class:0x10339e938> app/controllers/clients_controller.rb:10:in `index'
我究竟做错了什么?