When I tried to delete comments, the comments were not deleted from database and there is also an error undefined method `comment_path'...
_comment.html.erb
<% if current_user?(comment.user) %>
<%= link_to "delete", comment, method: :delete %>
<% end %>
comments_controller.rb
def destroy
@comment.destroy
flash[:success] = "Micropost deleted"
redirect_to request.referrer || root_url
end
microposts_controller.rb
def show
@user = User.find(params[:id])
@microposts = @user.microposts.paginate(page: params[:page])
@comments = @micropost.comments
end
routes.rb
resources :microposts do
resources :comments
end
Aucun commentaire:
Enregistrer un commentaire