我有一些与MongoDB,Mongoid映射器和设计的rails应用程序。授权用户可以创建,编辑,删除文章(脚手架)并评论这篇文章。我拿Ryan Bates screencast的评论模型例子,238集“Mongoid”。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。 我的错误在哪里?
您的问题需要一个更好的标题 - 以问题的形式。因为它是模糊的。 – jcollum
为什么不推出自己的认证?在rails 3.1中非常简单。观看这个railscast:http://railscasts.com/episodes/270-authentication-in-rails-3-1如果你绝对需要设计,我可以看一下,但有可能你自己做这个会更好/更简单。 –
@Tyler:Devise相当全面。它已经过很好的测试,并且已经有一段时间了。考虑到所涉及的时间,你必须提出一个非常有力的论证来滚动你自己。 – jcollum