Topic: I have a problem with the link in comments DESTROY.
I put a link to delete comments DESTROY.
The problem is that this link is also appearing when there is no comments.
It is as if null.
In the end, when "call" the comment supposedly empty, it returns null.
When I put the view to display a message with the index of the comment, it shows the index, as if he really had a comment there.
app / views / comments / _index.html.erb:
<% @ Post.comments.each_with_index do | comment, index |%>
<p> p = <% = index%> </ p>
<% If@post.moderated == false | | (@ && post.moderated comment.moderated)%>
<section>
<b> <% = simple_format (comment.author)%> </ b>
<p> <% = simple_format (comment.body)%> </ p>
</ section>
<% If comment.show_my_email%>
<p>
<b> E-mail: </ b>
<% =% Comment.email>
</ p>
<% End%>
<% = Link_to 'Destroy', comment, method :: delete, data: {confirm: 'Are you sure?' %}>
<hr />
<% end%>
<% end%>
controllers / posts_controller:
def show
@ post = Post.find (params [: id])
@ comment = @ post.comments.new
end
controllers / comments_controller:
def destroy
@ comment = Comment.find (params [: id])
@ post = @ comment.post
@ comment.destroy
respond_to do | format |
format.html {redirect_to post_path (@ post), notice: 'Comment deleted. "}
format.json {head: ok}
end
end
end
--------------------------------
Do you help me?
Last edited by MaryFeijo (2012-10-19 13:38:26)