[英]Syntax Error with rails unexpected ')'
Hi there I want to add a destroy action in post#show view I think I have creates the environment but when I place this code with a condition I have a message error. 嗨,我想在post#show视图中添加一个destroy动作,我想我已经创建了环境,但是当我将此代码放置在条件中时,出现消息错误。
<% if @user.comment == current_user %>
<% link_to @post_comment_path(post_id: @post.id, id: comment.id), method: :delete, data: { confirm: "Are you sure?" } do %>
<i class="fa fa-trash"></i>
<% end %>
<% end %>
I created a partial in post show#view which names _comments.html.erb 我在show#view后创建了一个名为_comments.html.erb的局部视图
here it is 这里是
<p class="text-center">Poster un commentaire</p>
<%= simple_form_for [post, post.comments.new] do |f| %>
<%= f.error_notification %>
<%= f.input :content, label: "Commentaire"%>
<%= f.submit "Envoyer", class: "btn btn-primary" %>
<% end %>
and it render like that <%= render 'comments' %>
它像这样
<%= render 'comments' %>
and above the partial (in post show#view) I do an iteration like that 在局部(在show#view之后)上方,我做了一个迭代
<ul class="list-unstyled">
<% @post.comments.each do |comment| %>
<li>
<p><% comment.content %></p>
<% end %>
</li>
</ul>
But nothing appears when I create a new message, I don't userstand why. 但是当我创建新消息时什么也没出现,我不明白为什么。
I give your more code details 我给你更多的代码细节
post.rb post.rb
has_many :comments, dependent: :destroy
comment.rb comment.rb
belongs_to :user
belongs_to :post
The route is: 路线是:
resources :posts do
resources :categories
resources :comments
end
Comments controller is 评论控制器为
class CommentsController < ApplicationController
before_action :set_post
def create
@comment = @post.comments.build(comment_params)
@comment.user_id = current_user.id
if @comment.save
flash[:success] = "You commented the hell out of that post!"
redirect_to :back
else
flash[:alert] = "There is a problem with your comment"
render root_path
end
end
def destroy
@comment = @post.comments.find(params[:id])
@comment.destroy
flash[:success] = "Comment deleted :("
redirect_to root_path
end
private
def set_post
@post = Post.find(params[:post_id])
end
def comment_params
params.require(:comment).permit(:content, :post_id, :user_id)
end
end
Thank you so much for your help. 非常感谢你的帮助。
您的link_to erb代码需要等号才能实际显示
<%= link_to post_comment_path(post_id: @post.id, id: comment.id), method: :delete, data: { confirm: "Are you sure?" } do
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.