我试图从vue.js应用程序中删除railsv5记录。它会被删除但是rails返回ActionController::RoutingError (No route matches [DELETE] "/"):
并且我不明白为什么?
Rails服务器在控制台中输出Started DELETE "/" for 127.0.0.1 at 2018-03-06 10:28:50 +0100
,但为什么它会重定向到" /"通过删除?
删除请求
deleteOffer() {
axios.delete(`/offers/${this.$route.params.id}.json`, {
data: {
id: this.offer.id,
authenticity_token: document.querySelector("meta[name='csrf-token']").getAttribute("content")
}
})
.then((response) => {
console.log(repsonse)
})
.catch((error) => {
this.errors.push(error)
console.log("[ERROR] Delete Offer from Rails: " + error.message);
});
}
的routes.rb
Rails.application.routes.draw do
root to: 'app#index'
resources :offers
end
控制器
class OffersController < ApplicationController
# DELETE /offers/1.json
def destroy
@offer.destroy
respond_to do |format|
format.json { render :json => {status: 'deleted'}, status: :deleted }
end
end
end