为什么我不能保存的对象与一个序列化的属性?(Why can't I save an obje

2019-10-17 21:39发布

我有...

/app/models/search.rb:

serialize :result  
def multisearch
  self.result = PgSearch.multisearch(self.term)
  self.status = "closed"
  self.save
  return result
end

/db/schema.rb:

create_table "searches", :force => true do |t|
  t.string   "term"
  t.string   "status"
  t.text     "result"
end

我收到以下错误,当我尝试'self.save?

ArgumentError: wrong number of arguments (2 for 1)
from /Users/steven/.rvm/gems/ruby-1.9.2-p320/gems/arel-3.0.2/lib/arel/expressions.rb:3:in `count'

我收到了类似的错误,当我测试result.serialize

ArgumentError: wrong number of arguments (0 for 1)
from /Users/steven/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.11/lib/active_record/attribute_methods/serialization.rb:49:in `serialize'

我怎样才能解决这个问题?

Answer 1:

答案是串行化之前转换为数组: self.result = PgSearch.multisearch(self.term).to_a



文章来源: Why can't I save an object with a serialized attribute?