B
B
bismoney2015-10-26 21:11:45
Ruby on Rails
bismoney, 2015-10-26 21:11:45

How to understand why destroy does not work?

Even I can’t understand the guys, everything seems to be right, but they don’t want to delete it.
In Post controller

def destroy
    @post.destroy
    respond_to do |format|
      format.html { redirect_to taskpanel_posts_path, notice: 'Новость успешно удалена.' }
      format.json { head :no_content }
    end
  end

I display the link
<%= link_to 'Удалить', taskpanel_posts_path(@post), method: :delete, data: { confirm: 'Точно удалить?' } %>

When clicked, it simply opens the post. Poke what else you can check.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CapeRatel, 2015-10-27
@bismoney

Hold on. Your route is not correct. type #rake routes in the console and see the paths how to do it right

def destroy
    @post = Post.find(params[:id])
    @post.destroy
    respond_to do |format|
      format.html { redirect_to taskpanel_posts_path, notice: 'Новость успешно удалена.' }
      format.json { head :no_content }
    end
  end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question