Hello,
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 message:
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, hope anyone can help me.
_comment.html.erb:
<%= 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?"} %>
comments_controller.rb:
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) companies#create
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) comments#destroy
hello_world GET /hello/world(.:format) hello#world