user603635
user603635

Reputation:

Error when deleting a page

I am new to Ruby on Rails and I am creating a basic blog application.

I am getting the following error when I have confirmed that I want to delete a post/page.

ActiveRecord::RecordNotFound in PagesController#destroy

Couldn't find Page with ID=21

{"authenticity_token"=>"JjjfnpIn4ogYhLWnbyGHjwLsy6YSgDHL+GZfOqkhSow=", "_method"=>"delete", "id"=>"21"}

I want the user to be redirected to the listing page when they have deleted the post, I understand that it looks as though problem is with the destroy action in the controller.

My code in there is currently:

  def destroy #Destroy action
    @page = Page.find(params[:id]) 
    @page.destroy 
    redirect_to page_url

I appreciate any advice on this.

Upvotes: 0

Views: 47

Answers (1)

Andrei S
Andrei S

Reputation: 6516

if you're deleting a Page, you shouldn't redirect back to it because.. it won't exist

maybe try redirect_to pages_url instead of page_url

Upvotes: 2

Related Questions