【发布时间】:2012-11-14 23:17:25
【问题描述】:
我正在使用带有 mongoid 2 的 Rails 3。我有一个 mongoid 类论坛,其中嵌入了多个主题。 主题 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
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 mongodb mongoid