From e2665a147cb7d6e678e5c6bf116bb03f8c8c5909 Mon Sep 17 00:00:00 2001 From: Mauricio Giacomini Girardello <mauriciogiacomini4@gmail.com> Date: Wed, 4 Nov 2015 11:27:06 -0200 Subject: [PATCH] adding remove learning object from collection route and controller action --- app/controllers/collections_controller.rb | 14 ++++++++++++-- config/routes.rb | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 6c9587dc5..229a453c6 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 97af4816a..19691a985 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' -- GitLab