开发者

Error when deleting a page

开发者 https://www.devze.com 2023-02-28 01:42 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号