我想在 ruby 中创建评论,但我有问题
1)posts_controller.rb
def comment
Post.find(params[:id]).comments.create(params[:comment])
flash[:notice] = "Added your comment"
redirect_to :action => "show", :id => params[:id]
end
2)show.html.erb
<%= form_tag :action => "comment", :id => @post %>
<%= text_area "comment", "message" %><br />
<%= submit_tag "Comment" %>
</form>
3)post.rb
class Post
include Mongoid::Document
include Mongoid::Timestamps::Created
include Mongoid::Timestamps::Updated
field :title, type: String
field :content, type: String
field :user_id, type: Integer
field :tag, type: String
field :owner, type: String
embeds_many :comments
accepts_nested_attributes_for :comments
end
4) 评论.rb
class Comment
include Mongoid::Document
include Mongoid::Timestamps::Created
include Mongoid::Timestamps::Updated
field :owner, type: String
field :message, type: String
field :voteup, type: Integer
field :votedown, type: Integer
embedded_in :post
end
我用过蒙古人
当我运行服务器有问题
路由错误
No route matches {:action=>"comment", :id=>#<Post _id: 5272289165af50d84d000001, created_at: 2013-10-31 09:53:21 UTC, updated_at: 2013-10-31 09:53:21 UTC, title: "firstpost", content: "ronaldo && bale", user_id: nil, tag: nil, owner: "boss_dongdoy@kuy.com">, :controller=>"posts"}