Ruby on rails 3 与designe的Mongoid关系

Ruby on rails 3 与designe的Mongoid关系,ruby-on-rails-3,mongodb,devise,mongoid,Ruby On Rails 3,Mongodb,Devise,Mongoid,我有一些使用MongoDB、Mongoid映射器和Desive的rails应用程序。А授权用户可以创建、编辑、删除帖子(脚手架)和评论这些帖子。我以Ryan Bates的视频为例,238集“Mongoid” comment.rb class Comment include Mongoid::Document field :name field :content embedded_in :post, :inverse_of => :comments end post.rb

我有一些使用MongoDB、Mongoid映射器和Desive的rails应用程序。А授权用户可以创建、编辑、删除帖子(脚手架)和评论这些帖子。我以Ryan Bates的视频为例,238集“Mongoid”

comment.rb

class Comment
  include Mongoid::Document
  field :name
  field :content
  embedded_in :post, :inverse_of => :comments
end
post.rb

class Post
      include Mongoid::Document
      field :name
      field :content
      validates_presence_of :name
      embeds_many :comments
    end
user.rb

class User
  include Mongoid::Document
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
    :recoverable, :rememberable, :trackable, :validatable

  field :username

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me

  has_many :comments
  references_many :post

end
但当我尝试注册新用户时,在注册表中按下“注册”,我看到了这个错误

Mongoid::Errors::MixedRelations in Devise::RegistrationsController#create

Referencing a(n) Comment document from the User document via a relational association is not allowed since the Comment is embedded.
我用Mysql db启动这个应用程序,然后决定进入mongo。
我的错在哪里

由于评论嵌入到帖子中,您应该让用户引用帖子。尝试删除用户中的
has\u many:comments

你的问题需要一个更好的标题——以问题的形式。既然它是模糊的,为什么不自己写呢?在rails 3.1中,它非常简单。看这条铁路史:如果你真的需要Desive,我可以看一看,但很可能你自己做会更好/更简单。@Tyler:Desive很全面。它经过了很好的测试,已经存在了一段时间。考虑到所需的时间,你必须提出一个非常有力的理由来支持你自己。jcollum,公平哈哈,但是如果他没有使用任何高级功能,他现在已经完成了实现。谢谢泰勒的推荐。我会试着去理解设计,并决定我是否需要它。我试过了。这是可行的,但是如果我需要获得所有用户的评论,那么你不应该在帖子中嵌入用户。你应该引用它。