0
無法添加嵌入式文檔。我正在嘗試添加嵌入用戶的標籤。未添加嵌入式文檔
user.rb
class User
include Mongoid::Document
field :name
validates_presence_of :name
validates_uniqueness_of :name, :email, :case_sensitive => false
attr_accessible :name, :email, :password, :password_confirmation
embeds_many :tags
embeds_many :tasks
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
tag.rb
class Tag
include Mongoid::Document
field :name
embedded_in :user, :inverse_of => :tags
references_many :tasks
end
tags_controller.rb
def create
#@user = User.find(:first, :conditions => {:_id => "4d3ae09bf5c4930b2b000004"})
@user = current_user
@tag = Tag.new(params[:tag])
@user.tags << @tag
@tag.save
redirect_to @tag, :notice => "Tag created!"
end
這是輸出到服務器時,我嘗試創建一個新的標籤。
Started POST "/tags" for 127.0.0.1 at 2011-02-18 13:46:03 -0500
Processing by TagsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"6p+Jova7Hol2v5LRReSp2fhNJ967EwkeIzAWyrChQRE=", "tag"=>{"name"=>"general"}, "commit"=>"Create Tag"}
db['users'].find({:_id=>BSON::ObjectId('4d39cd63f5c4930708000001')}, {}).limit(-1) MONGODB
db['users'].update({"_id"=>BSON::ObjectId('4d39cd63f5c4930708000001')}, {"$push"=>{"tags"=>{"name"=>"general", "_id"=>BSON::ObjectId('4d5ebe6bf5c493554d000002')}}}) Redirected to
http://localhost:3000/tags/4d5ebe6bf5c493554d000002 Completed 302 Found in 5ms
不確定是什麼問題或從哪裏開始。它實際上看起來像用戶被發現然後正在對標籤進行更新,但它不成功。
感謝
更新命令看起來不錯...控制器完成後用戶文檔的外觀如何? mongodb.log中是否顯示錯誤? – jared 2011-02-19 00:34:28