我正在使用带有 mongoid 2 的 Rails 3。我有一个 mongoid 类论坛,其中 embeds_many 主题。主题 embeds_many forumposts
当我尝试保存论坛帖子时,在我的控制器中执行以下操作...
@forum = Forum.find(params[:forum_id])
@forum.topics.find(params[:topic_id]).forumposts.build(:topic_id => params[:forumpost][:topic_id], :content => params[:forumpost][:content], :user_id => current_user.id,:posted_at => Time.now, :created_at => Time.now, :updated_at => Time.now)
if @forum.save
保存时我得到...
2012-11-14 23:15:39 UTC:Time 的未定义方法“每个”
为什么我会收到这个错误?
我的论坛帖子类如下...
class Forumpost
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Paranoia
field :content, type: String
field :topic_id, type: String
field :user_id, type: String
field :posted_at, type: DateTime
attr_accessible :content, :topic_id, :user_id, :posted_at, :created_at, :updated_at
validates :content, presence: true
validates :topic_id, presence: true
validates :user_id, presence: true
belongs_to :topic
belongs_to :user
end