我在ApplicationController中定义了方法
class ApplicationController < ActionController::Base
helper_method :get_active_gateway
def get_active_gateway(cart)
cart.account.gateways
end
end
当我在模型中调用此方法时
class Order < ActiveRecord::Base
def transfer
active= get_active_gateway(self.cart)
end
end
它抛出错误 undefined local variable get_active_gateway
。
所以我写道
class Order < ActiveRecord::Base
def transfer
active= ApplicationContoller.helpers.get_active_gateway(self.cart)
end
end
然后就是扔了 error undefined method nil for Nilclass
。
我在Rails 3.2.0中工作。