Rails error while trying to delete: "No route matches [GET]"


I am a newbie with Rails and I am having a problem with my study
application (Rails 3.2.6), when using Destroy links, I get the following
Routing Error
No route matches [GET] “/comments/2”

I can see that the Destroy link are calling a GET command instead of a
delete method.

I’ve searched a lot about this problem, but couln’t find the reason,
anyone can help me.


<%= comment.name %> said:

  • <%= simple_format comment.body %>*
  • Sent <%= time_ago_in_words comment.created_at %> ago*
  • <%= link_to “Destroy”, comment_path(comment), method: :delete , :data
    { :confirm => “Are you sure?”} %>*


  • class CommentsController < ApplicationController*

  • def create*

  • @job = Job.find(params[:job_id])*

  • @comment = @job.comments.build(params[:comment])*

  • if @comment.save*

  • flash[:notice] = “Comment was created with success!”*

  • else*

  • flash[:alert] = “Please fill in all fields to create a comment.”*

  • end*

  • redirect_to @job*

  • end*

  • def destroy*

  • @comment = Comment.find(params[:id])*

  • @comment.destroy*

  • redirect_to @comment.job, notice: “Comment destroyed with success.”*

  • end*

  • end*

rake routes:

  •       root        /                                jobs#premium*

companies_login GET /companies/login(.:format) login#new

  •           POST   /companies/login(.:format)       login#create*
  • companies POST   /companies(.:format) 


  • new_company GET /companies/new(.:format) companies#new*
  • job_comments POST /jobs/:job_id/comments(.:format) comments#create*
  •      jobs GET    /jobs(.:format)                  jobs#index*
  •           POST   /jobs(.:format)                  jobs#create*
  •   new_job GET    /jobs/new(.:format)              jobs#new*
  •  edit_job GET    /jobs/:id/edit(.:format)         jobs#edit*
  •       job GET    /jobs/:id(.:format)              jobs#show*
  •           PUT    /jobs/:id(.:format)              jobs#update*
  •           DELETE /jobs/:id(.:format)              jobs#destroy*
  •   comment DELETE /comments/:id(.:format) 


  • hello_world GET /hello/world(.:format) hello#world*

Post your route.rb plz.

Em segunda-feira, 15 de junho de 2015 03:25:54 UTC-3, Arthur Flores


It hasn’t been all that long since I’ve used 3.2, but I think you’re
using the wrong syntax. Please look at
shows the link_to method at that time.

Also, look at the html that is generated for the view and see if you can
tell what’s happening.

I wish I could be of more help…


On Mon, Jun 15, 2015 at 10:51 PM, Rafael B. [email protected]

Try this please it will work
<%= link_to “Destroy”, {:controller => “comment”, :action => “destroy”,
:id => comment.id }%>

Try adding those to your application.js file instead. Then they’ll be
concatenated and minimized by Sprockets for faster service.


Hello everyone,

Thanks a lot for your help.
I finally found what was the problem, the jquery wasn’t working. I
the HTML code, everything was correct, but in the time of the event the
jquery wasn’t working,

The solution is in this post:

In the file “\app\views\layouts\application.html.erb”, inside the
tag I just included this line:
<%= javascript_include_tag :jquery, :jquery_ujs %>

So, now the application recognizes the Delete method, and it also solve
another issue that I was having. The ajax commands using the command
true” wasn’t working, it was calling an html request instead of a JS
request, so everything working good now.

Thanks a lot for your help.

Arthur Duarte

Em terça-feira, 16 de junho de 2015 07:51:37 UTC-3, Saravanan B