无法在typed_store中使用:text

问题描述

我尝试做

  typed_store :Meta do |s|
    s.string :name
    s.text   :instructions
  end

即使列出herekey not found: :text也给我一个错误:text

[:string,:text,:integer,:float,:time,:datetime,:date,:boolean,:decimal,:any].each do |type|

有人知道我在做什么错吗? s.string有效但是s.text

解决方法

您确定gem允许text作为允许的类型吗?

# lib/active_record/typed_store/field.rb#L38

TYPES = {
      boolean: ::ActiveRecord::Type::Boolean,integer: ::ActiveRecord::Type::Integer,string: ::ActiveRecord::Type::String,float: ::ActiveRecord::Type::Float,date: ::ActiveRecord::Type::Date,time: ::ActiveRecord::Type::Time,datetime: ::ActiveRecord::Type::DateTime,decimal: ::ActiveRecord::Type::Decimal,any: ::ActiveRecord::Type::Value,}

    def lookup_type(type,options)
      TYPES.fetch(type).new(**options)
    end