Reputation: 1974
I'm trying to make an ajax call to controller action.
ajax call:
$.ajax({url: "offerings/remove_from_sale", type: "POST"})
controller:
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
routes:
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
There is an error
No route matches [POST] "/manage/ground_service/offerings/remove_from_sale"
What am I doing wrong? Should I put remove_from_sale
action to offerings_controller
? Please ask if you need more information.
Upvotes: 0
Views: 82
Reputation: 32955
If your url doesn't start with a slash, it will add it to the current page url. Try putting a slash at the start of your ajax url.
Upvotes: 0
Reputation: 51191
remove_from_sale
is not default resource route, so you must specify it:
resources :offerings, only: :update do
collection do
post :remove_from_sale
end
end
Upvotes: 1