0

So this is my first experience with Rails, I did everything according to http://guides.rubyonrails.org/getting_started.html#generating-a-model

And now i can't destroy a commment... I tried several google search, i tried to remove the file then generate it again, nothing works... My comments_controller.rb

class CommentsController < ApplicationController
  def index
  end

  def show
  end

  def new
  end

  def edit
  end

  def create
    @article = Article.find(params[:article_id])
    @comment = @article.comments.create(comment_params)
    redirect_to article_path(@article)
  end

  def destroy
    @article = Article.find(params[:article_id])
    @comment = @article.comments.find(params[:id])
    @comment.destroy!
    redirect_to article_path(@article)                      
  end

  private
    def comment_params
      params.require(:comment).permit(:commenter, :body)
    end

end

    p>
  <strong>Commenter:</strong>
  <%= comment.commenter %>
</p>
 

And my _comment.html.erb is

<p>
  <strong>Comment:</strong>
  <%= comment.body %>
</p>
 
<p>
  <%= link_to 'Delete the comment', [comment.article, comment],
               method: :delete,
               data: { confirm: 'Are you sure?' } %>
</p>

I receive this when i click on the "Delete the comment" button

Missing template comments/show, application/show with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: * "/root/blog/app/views"

But that shouldn't be the problem since I'm doing a redirect to the article path ? Right?? I sure hope this is a typo somewhere but now I can't find it....

Edit : this is the text of the button

<form action="/articles/2/comments/1" class="button_to" method="post">    <div><input type="submit" value="Delete the comment"  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data="{:confirm=>&quot;Are you sure?&quot;}" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method="delete"><input name="authenticity_token" type="hidden" value="rW+wymZlJp2cMrhGUX31Y/vLz+qZ1VHTEVHaavS7YTU="></div></form>
  • Passing an `@article` to the `article_path` will redirect it to the `show` page for that article. Where do you want to redirect to? Back to the index? – Paul Richter Mar 05 '15 at 20:51
  • I want to redirect to the article page. So that would be to the show page of article, not the show page of comment... – Vincent Gagnon Mar 05 '15 at 20:52
  • Sorry my bad, I misunderstood. Read it too quickly. So the problem in a nutshell is that the link is sending a GET request, rather than a DELETE. Does [this answer](http://stackoverflow.com/a/3775095/877472) make any difference? – Paul Richter Mar 05 '15 at 20:56
  • Well this is my header, ` Mon blog <%= stylesheet_link_tag 'application', media: 'all', 'data-turb$ <%= javascript_include_tag 'application', 'data-turbolinks-track' $ <%= csrf_meta_tags %> <%= yield %> ` I dont have the :default but it's no longer supported and i have the 'application' instead as described in the comment below – Vincent Gagnon Mar 05 '15 at 21:04
  • Sorry for the ugly copy-paste, don't know how to paste it like in the main subject.. – Vincent Gagnon Mar 05 '15 at 21:06
  • Oh i found what you wanted to show me, the `buton_to` still doesn't work but there is a different error, `No route matches [POST] "/articles/2/comments/1" ` – Vincent Gagnon Mar 05 '15 at 21:10
  • There a little edit button at the bottom of your question if you want to add more information, but its readable enough anyways. Can you verify that you have `//= require jquery` and `//= require jquery_ujs` in your `application.js` manifest? – Paul Richter Mar 05 '15 at 21:11
  • Also, take a look at [this answer](http://stackoverflow.com/a/20934983/877472); can you verify that the link looks like that person describes (or at least, doesn't look like the screwed up version)? – Paul Richter Mar 05 '15 at 21:12
  • Already checked for the //= require jquery and its all there – Vincent Gagnon Mar 05 '15 at 21:18
  • Added the inspect element of the button on my server – Vincent Gagnon Mar 05 '15 at 21:22

1 Answers1

0

Looks like the method :delete of the link is not working.

Make sure you have javascript turned on and add

<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>

to the <head> of your layout/application