1
我想了解为什么我的类方法不被识别。下面是我的代码:为什么我的班级方法不被识别?
wiki_patch.rb
require_dependency 'wiki_content'
module WikiRecipientPatch
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
alias_method_chain :recipients, :send_wiki_mail
end
end
end
module InstanceMethods
def self.set_mail_checker(mail)
@mail_checker = mail
end
end
Rails.configuration.to_prepare do
WikiContent.send(:include, WikiRecipientPatch)
end
controller.rb
WikiContent.set_mail_checker(params[:mail_checker_wiki])
我收到此错误:
NoMethodError (undefined method `set_mail_checker' for #<Class:0x4876560>):
任何想法,为什么会发生什么的解决方案是?
使用你的提示,我得到了以下错误:'NoMethodError(用于InstanceMethods :: WikiContent未定义的方法'set_mail_checker”:类)'。我做错事情了? – kamusett
@ user2195342,可能。因为答案中的代码有效。 –
我忘了提及我的模块内有两种方法。模块包含了其中一种方法。另一个是上面列出的。为了简化问题,我隐藏了另一个。 – kamusett