Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 路由错误没有与[DELETE]匹配的路由/“主题”;_Ruby On Rails_Controller_Routes - Fatal编程技术网

Ruby on rails 路由错误没有与[DELETE]匹配的路由/“主题”;

Ruby on rails 路由错误没有与[DELETE]匹配的路由/“主题”;,ruby-on-rails,controller,routes,Ruby On Rails,Controller,Routes,正在尝试获取删除操作以使主题控制器正常工作。 这是我的主题控制器 def destroy @topic = Topic.find(params[:id]) if @topic.destroy flash[:notice] = "\"#{@topic.title}\" Topic was deleted!" redirect_to topics_path(@topic) else flash.now[:alert] = "An error occurred. Please try a

正在尝试获取删除操作以使主题控制器正常工作。 这是我的主题控制器

def destroy
@topic = Topic.find(params[:id])

if @topic.destroy
  flash[:notice] = "\"#{@topic.title}\" Topic was deleted!"
  redirect_to topics_path(@topic)
else
  flash.now[:alert] = "An error occurred. Please try again."
  render :show
end
结束

我的路线:

 resources :topics do
    resources :bookmarks, except: [:index]
  end
“我的索引”视图上的“我的删除”链接:

<%= link_to "Delete Topic", @topic, method: :delete, class: 'btn btn-danger', data: { confirm: 'Are you sure you want to delete this topic?' } %>


真的不明白我遗漏了什么。

尝试以下更改:

def destroy
  @topic = Topic.find(params[:id])

  if @topic.destroy
    flash[:notice] = "\"#{@topic.title}\" Topic was deleted!"
    redirect_to topics_path
  else
    flash.now[:alert] = "An error occurred. Please try again."
    render :show
  end
end
删除链接:

<%= link_to "Delete Topic", topic_path(@topic), method: :delete, class: 'btn btn-danger', data: { confirm: 'Are you sure you want to delete this topic?' } %>

多态url(@topic)给了你什么?我的猜测是,您要么将
@topic
重新分配给了无意中发生的事情,要么以某种方式将
ActionDispatch::Routing::PolymorphicRoutes
搞砸了,从而给出了收集路线。