2013-03-27 66 views
1

我有...爲什麼我無法保存具有序列化屬性的對象?

/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' 

我該如何解決這個問題?

回答

0

答案是在序列化之前轉換爲數組:self.result = PgSearch.multisearch(self.term).to_a

相關問題