NoMethodError - InlineTextStorage:Class 的未定义方法'update'



我有一个问题的方法update。当我在控制器中呼叫他时,我失败了NoMethodError - undefined method 'update' for InlineTextStorage:Class原因是什么呢?

class StaticAreasController < ApplicationController
  def update
    @static_area = InlineTextStorage.update("key", "value")
  end
end
class InlineTextStorage
  def update(key, value)
    inline_text = StaticArea.find_by_key!(key)
    inline_text.text = value
    @@texts[key] = value
    update_cache
  end
end

您正在尝试将实例方法调用为类方法。您必须在名称中添加self.

class InlineTextStorage
  def self.update(key, value)
    inline_text = StaticArea.find_by_key!(key)

最新更新