【发布时间】:2014-11-02 19:01:41
【问题描述】:
我正在尝试使用 hstore 数组类型的 postgreSQL 列,一切似乎都运行良好。但是,我的视图转义了数组并将其转换为格式错误的字符串。我的代码如下所示:
迁移:
class AddVariantsToItem < ActiveRecord::Migration
def change
execute 'CREATE EXTENSION hstore'
add_column :items, :variants, :hstore, array: true, default: []
end
end
现在,如果我要在 rails 控制台 中使用 Item.last.variants,它会给我一个合适的数组
> Item.last.variants
#=> [{"name"=>"Small", "price"=>"12.00"}, {"name"=>"Medium", "price"=>"20.00"}]
但是,在苗条视图中使用完全相同的代码会给我一个转义字符串:
div
= debug Item.last.variants
/ Gives me:
/ '{"\"name\"=>\"Small\", \"price\"=>\"12.00\"","\"name\"=>\"Medium\", \"price\"=>\"20.00\""}'
使用raw、== 或.html_save 不会改变任何东西。谁能告诉我我能做些什么吗?
【问题讨论】:
-
Item.last.variants.to_yaml会得到什么? -
这不是同一个代码 - 你打电话给
debug -
好吧,
debug给了我与将该变量放入 textarea 值完全相同的输出(这是我现在需要的)
标签: ruby-on-rails ruby postgresql hstore