我正在尝试对控制器操作进行ajax调用。
ajax电话:
$.ajax({url: "offerings/remove_from_sale", type: "POST"})
控制器:
class Manage::GroundServiceController < ApplicationController
def remove_from_sale
Ts::User.all.each do |user|
unless user.ground_service == nil
if user.ground_service.ID == params[:id]
true
end
end
end
end
end
路线:
namespace :manage do
resources :ground_service, except: [:new, :create, :edit, :update, :destroy] do
collection do
get :edit
get :products
resources :events, only: [:show, :update] do
member do
post :accept
end
end
resources :offerings, only: [:update, :remove_from_sale]
resources :prices, only: [:update]
end
end
end
有错误
No route matches [POST] "/manage/ground_service/offerings/remove_from_sale"
我做错了什么?我应该remove_from_sale
对offerings_controller
采取行动吗?请询问您是否需要更多信息。
答案 0 :(得分:1)
remove_from_sale
不是默认资源路由,因此您必须指定它:
resources :offerings, only: :update do
collection do
post :remove_from_sale
end
end
答案 1 :(得分:0)
如果您的网址没有以斜杠开头,则会将其添加到当前网页网址。尝试在ajax网址的开头添加斜杠。