我正在从 XML 流中提取一系列字符串并将它们存储在 mySQL 数据库中(尝试使用 VARCHAR 和 TEXT)。在数据库中每个数组的开头,我得到 ---
,然后是 []
(如果它是空白数组)或值。
Rake 任务代码:
@issue = Array.new
items.each do |item| #items is the parsed elements from XML
link_key = item.xpath('key').inner_text
@issue << link_key
Rails.logger.debug("Issue: #{@issue.inspect}")
end
数据库值示例:
“---[]”
-或-
“--- - CR-3528”
不确定还有什么用处。
最佳答案
那是因为您正在序列化一个数组。
处理此问题的一种方法是使用 serialize
将字段标记为序列化 ( docs ):
serialize :issue
参见 this了解更多详细信息。
如果您将值存储为文本,则您不应该看到这一点 - 它只是文本。
关于mysql - Rails 和 MySQL : Array winds up with ---[] or --- stored in the DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8301342/