【发布时间】:2014-05-07 00:29:51
【问题描述】:
我正在尝试使用 Mongoid 在 Rails 4 中的两个实体之间建立 1-N(一对多)关系。到目前为止,我已经创建了一个带有“博客”和“评论”的简单应用程序(每个博客包含多个 cmets)。
我使用has_many 属性来定义关系。这是我到目前为止所得到的......
class Blog
include Mongoid::Document
include Mongoid::Timestamps
has_many :comments, validate: false
field :title, type: String
field :content, type: String
end
class Comment
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :blog
field :title, type: String
field :content, type: String
end
这是我的 Blog#Show 视图文件的样子 https://github.com/som-poddar/Mongo_One_Many/blob/master/app/views/blogs/show.html.erb
经过几次尝试,我总是以......
Showing /Users/spoddar/work/Mongo_One_Many/app/views/comments/_form.html.erb where line #1 raised:
undefined method `comments_path' for #<#<Class:0x007f9f1d08e5f8>:0x007f9f1f9b6458>
有人可以帮帮我吗? 完整源代码https://github.com/som-poddar/Mongo_One_Many
我的路线...
Prefix Verb URI Pattern Controller#Action
blog_comments GET /blogs/:blog_id/comments(.:format) comments#index
POST /blogs/:blog_id/comments(.:format) comments#create
new_blog_comment GET /blogs/:blog_id/comments/new(.:format) comments#new
edit_blog_comment GET /blogs/:blog_id/comments/:id/edit(.:format) comments#edit
blog_comment GET /blogs/:blog_id/comments/:id(.:format) comments#show
PATCH /blogs/:blog_id/comments/:id(.:format) comments#update
PUT /blogs/:blog_id/comments/:id(.:format) comments#update
DELETE /blogs/:blog_id/comments/:id(.:format) comments#destroy
blogs GET /blogs(.:format) blogs#index
POST /blogs(.:format) blogs#create
new_blog GET /blogs/new(.:format) blogs#new
edit_blog GET /blogs/:id/edit(.:format) blogs#edit
blog GET /blogs/:id(.:format) blogs#show
PATCH /blogs/:id(.:format) blogs#update
PUT /blogs/:id(.:format) blogs#update
DELETE /blogs/:id(.:format) blogs#destroy
【问题讨论】:
标签: ruby-on-rails ruby mongodb ruby-on-rails-4 mongoid