I have an ajax call that works in a .js
file, using:
...
update: function(){
$.ajax({
url: '/groups/order_links',
...
but I would rather use the route path
I made the file extension .js.erb
and I tried adding:
...
update: function(){
$.ajax({
url: "#{order_links_groups_path}",
...
or
...
url: "#{order_links_groups_url}",
...
but I am getting a 404 in either case - [HTTP/1.1 404 Not Found 76ms]
From a POST http://localhost:3000/groups/49
rake routes
shows my routes include:
...
PUT /groups/:group_id/links/:id(.:format) links#update
DELETE /groups/:group_id/links/:id(.:format) links#destroy
order_links_groups POST /groups/order_links(.:format) groups#order_links
groups GET /groups(.:format) groups#index
POST /groups(.:format) groups#create
new_group GET /groups/new(.:format) groups#new
edit_group GET /groups/:id/edit(.:format) groups#edit
which are defined with:
resources :groups do
resources :links
collection do
post 'order_links'
end
end
groups_controller
has
class GroupsController < ApplicationController
...
def order_links
params[:link].each_with_index do |id, index|
Link.where(id: id).update_all(['position = ?',index+1])
end
render :nothing => true
end
...
Rails 4.1