我在 ruby on rails 上使用 mongoid 的保存选项,它给我一个错误
can't convert Fixnum into String
我的模型文件是
产品.rb
class Product
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Versioning
field :product_role, :type => String
field :status_id, type: Moped::BSON::ObjectId
field :status_name,type: String
end
状态.rb
class Status
include Mongoid::Document
field :name, type: String
index :name => 1
end
控制器代码是
product_id = "523741002a6c6e8d1a000002",
status_name = "Pending Review"
product_detail_status = Product.where(id:product_id).first
status = Status.where(name:status_name).first
puts "##############"
puts product_detail_status.id.to_s
puts status.name.to_s
puts status.id.to_s
puts "##############"
product_detail_status.status_name = status.name.to_s
product_detail_status.status_id = status.id
product_detail_status.save
我可以查看puts中的值,但它没有通过在
product_detail_status.save上抛出错误的方式保存为“无法将Fixnum转换为字符串”
Completed 500 Internal Server Error in 657ms
TypeError - can't convert Fixnum into String:
mongoid (3.1.4) lib/mongoid/versioning.rb:53:in `revise'
activesupport (3.2.13) lib/active_support/callbacks.rb:407:in `
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
mongoid (3.1.4) lib/mongoid/callbacks.rb:130:in `run_callbacks'
mongoid (3.1.4) lib/mongoid/persistence/modification.rb:24:in `prepare'
mongoid (3.1.4) lib/mongoid/persistence/operations/update.rb:45:in `persist'
mongoid (3.1.4) lib/mongoid/persistence.rb:145:in `update'
mongoid (3.1.4) lib/mongoid/persistence.rb:82:in `save'
提前致谢