我在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
我遇到了一个问题,错误提示为 undefined method nil for Nilclass
。
我正在使用Rails 3.2.0。