I got my app working so that the user can only delete their own comments but now im trying to add a link to the site but i only want the creator of the comment to be able to see the link.
I tried doing
<% if current_user %>
but when i do that it shows up on all comments and not just the user. I can do
<% if current_user.admin %>
and that restricts only the admin to be able to see the delete links. I’ve also tried
<% if @comment.user_id == current_user.id %>
that doesent work either. How can i do it so that the comment creator can only see the comments?
heres my view
_comments.html.erb
<div class="container">
<% @comments.each do |comment| %>
<div class="comment">
<div class="gravatar_border">
<%= gravatar_for comment.user, size: '49' %>
</div>
<div class="user_info_comments">
<b><%= comment.user.name %></b>
<%= comment.created_at.strftime("%b. %d %Y") %>
</div>
<div class="user_comments">
<%= simple_format comment.content %>
<%= pluralize comment.reputation_value_for(:votes).to_i, "vote" %>
<%= link_to "", vote_comment_path(comment, type: 'up'), method: "post", class: ' icon-thumbs-up' %>
<%= link_to "", vote_comment_path(comment, type: 'down'), method: "post", class: ' icon-thumbs-down' %>
<% if @comment.user_id == current_user.id %>
<%= link_to 'delete', comment, method: :delete, confirm: 'you sure?' %>
<% end %>
</div>
</div>
<% end %>
<br />
</div>
heres my controller
comments_controller.rb
def destroy
@comment = Comment.find(params[:id])
if @comment.user_id == current_user.id
@comment.destroy
flash[:notice] = "comment deleted!"
else
flash[:error] = "not allowed"
end
redirect_to :back
end
heres a link to the site http://www.batman-fansite.com
and should work)