ActiveRecord::ConnectionAdapters::Column.value_to_boolean
是否有“酷 child 认可”的替代品?在 rails 3.2 中?
最佳答案
在 Rails 4.2 中,这看起来是一种可行的方法:
ActiveRecord::Type::Boolean.new.type_cast_from_database(value)
哪个幕后黑手会这样做
if value == ''
nil
else
ConnectionAdapters::Column::TRUE_VALUES.include?(value)
end
或者在 Rails 5 中:
ActiveRecord::Type::Boolean.new.cast(value)
这似乎在这里结束:
def cast_value(value)
if value == ''
nil
else
!FALSE_VALUES.include?(value)
end
end
关于ruby-on-rails - value_to_boolean 已弃用;什么是好的替代品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16848052/