Tag: hstore

我可以使用Rails在hstore中存储数组

我想保存这样的数据: User.create(name:”Guy”, properties:{url:[“url1″,”url2″,”url3″], street_address:”asdf”}) 我可以在Rails 4中这样做吗? 到目前为止,我尝试过迁移: add_column :users, :properties, :hstore, array: true 但是当我在hstore中保存数组时,它返回错误: PG::InvalidTextRepresentation: ERROR: array value must start with “{” or dimension information

rails 4强参数+动态hstore键

我在使用Hstore和动态访问器克服Rails 4中新的强params需求时遇到了问题 我有一个Hstore列,名为:content ,我想用它来存储多种语言的内容,即:en, :fr等。我不知道在模型或控制器中预先设置哪种语言。 store_accessor :content, [:en, :fr] #+226 random other il8n languages won’t work. 如何在rails 4中为一列覆盖强params(或允许动态hstore键)? params.require(:article).permit( :name, :content, :en, :fr #+226 random translations ) 缺乏… params.require(:article).permit! 这当然有效。

如何在rails中解析和显示hstore键/值

我有一个postgres hstore存储json字符串的数据类型。 我希望能够在rails html页面上解析并显示键/值。 不知何故,我只是不知道如何在数据字段上运行解析并显示字符串中列出的每个键/值。 <– this is the hstore json string <– this is an error, just to show 例如,payment_account.data包含{“hello”=>“world”,“great”=>“job”} 这是index.html.erb代码。 https://gist.github.com/axilaris/9174206 我该怎么做才能做到这一点? 解析hstore字符串以在rails中显示查询结果?

模型属性包含对象的集合

我有主模型页面,它是容器。 该页面可以包含一些待办事项列表,备注,文件和讨论。 我们的想法是让它们按特殊顺序排列。 Page.last.container # [Todolist_obj, Note_obj, File_obj, Note_obj, Discussion_obj, File_obj, File_obj] 所以我开始使用Mongodb 或者我也考虑过将Postgres与hstore一起使用,但不知道它是否会有所帮助 或者可能只是任何数据库并在获取页面时反序列化所有对象,并在保存时序列化对象 或者我可以使用MTI制作超类Item并从中inheritance所有包含对象,并使Page有很多关系。 所以我不知道哪种方式最好? 或者有更好的方法?

没有运算符匹配给定的名称和参数类型

我设置我的Rails 3.2.x应用程序以使用PostgreSQL HStore但我收到了一个错误。 看起来环境没有拾取hstore扩展。 我已经重新启动了我的机器,检查了数据库扩展等。 当我尝试执行时: User.where(“settings @> (:key => :value)”, :key => “setting_x”, :value => “test”) 我收到一个错误:( @>无法识别,即没有安装扩展名hstore ?) HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. 我的Rails应用程序设置是: Gemfile.rb: gem ‘activerecord-postgres-hstore’ 移民: add_column :users, :settings, :hstore execute “CREATE INDEX CONCURRENTLY users_gin_settings ON users USING […]

Hstore和Rails

我正在尝试使用最新版本的activerecord-postgres-hstore gem在Rails 3.2.9项目中使用Hstore,并且我在使用ActiveRecord提供的store_accessor获取Hstore中的值时遇到了一些麻烦。 我的模型看起来像这样: class Person < ActiveRecord::Base serialize :data, ActiveRecord::Coders::Hstore attr_accessible :data, :name store_accessor :data, :age, :gender end 当我进入rails控制台时,我得到的是: Loading development environment (Rails 3.2.9) 1.9.3-p327 :001 > p = Person.find(3) Person Load (9.8ms) SELECT “people”.* FROM “people” WHERE “people”.”id” = $1 LIMIT 1 [[“id”, 3]] => #”34″, “gender”=>”male”}, created_at: “2012-12-07 15:01:53”, updated_at: “2012-12-07 15:27:40”> […]