ruby on rails 3 - Embedded Document not being added -


having trouble adding embedded document. trying add tag embedded in user.

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 

this output server when try create new tag.

started post "/tags" 127.0.0.1 @ 2011-02-18 13:46:03 -0500    processing tagscontroller#create 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  http://localhost:3000/tags/4d5ebe6bf5c493554d000002 completed 302 found in 5ms 

not sure issue or start. looks user found update being made tags not successful.

thanks

the tags class in model embedded inside of user (via embeds_many association), rather table on own. following updates in controller, should have this:

> db.users.find()  {      _id: objectid('4d39cd63f5c4930708000001'),     tags: [         {             _id: objectid('4d5ebe6bf5c493554d000002'),             name: "general"         }     ] } 

using mongoid, can have tags appear in own collection replacing "embeds_many" "references_many".

in comments above, you'll see issue berek-bryan having had tag being added. expected tag added in own collection, hence question. actually, tags being added right users collection.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -