diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 6c9587dc55c5c01959d48d3d5fd48559ec4adccf..229a453c69f44cce1c12699914abc6214cee94d1 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -64,10 +64,20 @@ class CollectionsController < ApplicationController def add_learning_object learning_object = learning_object_repository.find params[:learning_object_id] @collection.add learning_object - collection_repository.save_learning_objects @collection + + if request.xhr? && collection_repository.save_learning_objects(@collection) + render json: {status: true} + end + end + + # DELETE /collections/1/learning_object/43 + def remove_learning_object + #learning_object = learning_object_repository.find params[:learning_object_id] + #@collection.add learning_object + #collection_repository.save_learning_objects @collection if request.xhr? - render json: {collections: @collection.learning_objects.as_json} + render json: {status: true} end end diff --git a/config/routes.rb b/config/routes.rb index 97af4816a90ba7caca44c7c601a399c51c935b3f..19691a9852ba50d8334516fa02716c9b4669253d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -49,6 +49,9 @@ Rails.application.routes.draw do member do # add a learning object for some collection post '/learning_object/:learning_object_id', as: :add_learning_object, action: :add_learning_object + + # remove a learning object for some collection + delete '/learning_object/:learning_object_id', as: :destroy_learning_object, action: :remove_learning_object end end @@ -66,7 +69,6 @@ Rails.application.routes.draw do get '/autocomplete' => 'search#autocomplete' get '/subject/:id' => 'welcome#subject', as: 'subject_index' - get '/collection' => 'welcome#collection' get '/add_file' => 'welcome#add_file' get '/signup' => 'welcome#signup' get '/follow_collection' => 'welcome#follow_collection'