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
搞砸了,从而给出了收集路线。