让用户 post 评论和在页面上加载评论时出错
Having error while letting users post comments and loading comments on a page
我收到以下错误:
syntax error, unexpected keyword_end, expecting end-of-input
这是我的 Comments_controller 文件,
class CommentsController < ApplicationController
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.build(params[:comment])
@comment.save
redirect_to @posts
end
def destroy
end
end
end
这是HTML使用它,
<h1><%= @post.title %></h1>
<%= @post.text %>
<h2>Comments</h2>
<% @post.comments.each do |comment| %>
<p><%= comment.text %></p>
<p><%= time_ago_in_words comment.created_at %> ago </p>
<% end %>
<%= form_for [@post, @post.comments.build] do |f| %>
<p><%= f.text_area :text, :size => "40x10" %></p>
<p><%= f.submit "Post Comment" %></p>
<% end %>
<p>
<%= link_to "Back", posts_path %>
|
<%= link_to "Edit", edit_post_path(@post) %>
|
<%= link_to "Delete", @post, method: :delete, data: { confirm: 'Are you sure?' } %>
</p>
因此,当用户 post 的评论或当用户尝试加载评论页面时,会发生此错误。
class CommentsController < ApplicationController
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.build(params[:comment])
@comment.save
redirect_to @posts
end
def destroy
end
end
一端在你的控制器代码中是额外的
我收到以下错误:
syntax error, unexpected keyword_end, expecting end-of-input
这是我的 Comments_controller 文件,
class CommentsController < ApplicationController
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.build(params[:comment])
@comment.save
redirect_to @posts
end
def destroy
end
end
end
这是HTML使用它,
<h1><%= @post.title %></h1>
<%= @post.text %>
<h2>Comments</h2>
<% @post.comments.each do |comment| %>
<p><%= comment.text %></p>
<p><%= time_ago_in_words comment.created_at %> ago </p>
<% end %>
<%= form_for [@post, @post.comments.build] do |f| %>
<p><%= f.text_area :text, :size => "40x10" %></p>
<p><%= f.submit "Post Comment" %></p>
<% end %>
<p>
<%= link_to "Back", posts_path %>
|
<%= link_to "Edit", edit_post_path(@post) %>
|
<%= link_to "Delete", @post, method: :delete, data: { confirm: 'Are you sure?' } %>
</p>
因此,当用户 post 的评论或当用户尝试加载评论页面时,会发生此错误。
class CommentsController < ApplicationController
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.build(params[:comment])
@comment.save
redirect_to @posts
end
def destroy
end
end
一端在你的控制器代码中是额外的