<%= simple_form_for :addcomments, :url => addcomments_post_path, :multipart => true ,:method => 'post' do |f| %>
<%= f.input :title %>
<%= f.input :body %>
<%= f.button :submit %>
这是我对帖子添加评论的部分视图,下面是我的帖子->显示视图
<div>
<h4>Comments </h4><br>
<%= @all_comments.each do |t| %>
<h3><%= t.title %></h3> <br>
<h4><%= t.body %></h4> <br>
<% end %>
<%= render :partial => 'addcomment' %>
</div>
Comments_controller.rb 是
class CommentsController < ApplicationController
# before_filter :load_commentable
def addcomments
@post = Post.find(params[:id])
@user = current_user
@comment = Comment.build_from(@post,@user,params[:comment])
if @comment.save
redirect_to post_url
else
redirect_to post_url
end
end
end
路由.rb
resources :comments do
member do
post 'addcomments', to: 'comments#addcomments'
end
end
当我运行此代码并单击 post-> show 时,出现错误
The action 'addcomments' could not be found for CommentsController