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:
开发者_如何学Go def destroy #Destroy action
@page = Page.find(params[:id])
@page.destroy
redirect_to page_url
I appreciate any advice on this.
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
精彩评论