I am trying to delete a post using the code below:
<%= link_to \'Destroy\', post, :method => :delete, :onclick => \"return confirm(\'Are you sure you wa
This is the Rails way:
<%= link_to 'Destroy', post, confirm: 'Are you sure?', method: :delete %>
If the post isn't deleted then the problem lies in your controller. Are you sure you've correctly implemented the #destroy
action? What's the output you're getting in your server logs?
UPDATE: Change your action to:
def destroy
@post = Post.find(params[:id])
respond_to do |format|
if @post.destroy
format.html { redirect_to posts_url }
format.json { head :no_content }
else
format.html # do something here
format.json { head :no_content }
end
end
end