【发布时间】:2015-03-27 17:10:53
【问题描述】:
我创建了一个辅助方法,我想在模型类方法上运行它并得到一个方法未找到错误。
lib/model_helper
module ModelHelper
def method_i_want_to_use
puts "I want to use this method"
end
end
模型/foo
class Foo < ActiveRecord::Base
include ModelHelper
def self.bar
method_i_want_to_use
end
end
这个设置给了我一个无方法错误。
【问题讨论】:
-
不要在模型中使用助手,这不是它们的用途。请改用关注点。
-
@BroiSatse 正确.. 正确。
标签: ruby-on-rails ruby activerecord module helper