Skip to content
Snippets Groups Projects
Commit 83d26921 authored by Giovanne Marcelo's avatar Giovanne Marcelo
Browse files

adding taggable concern

parent 77e64ce3
No related branches found
No related tags found
No related merge requests found
module TaggableController
extend ActiveSupport::Concern
included do
before_action :authenticate_user!, only: [:tagging, :untagging]
end
# POST /v1/learning_objects/1/tagging
# POST /v1/learning_objects/1/tagging.json
def tagging
taggable.tag_list.add(params[:name])
if taggable.save
render json: @taggable, status: :ok
else
render json: @taggable.errors, status: :unprocessable_entity
end
end
# DELETE /v1/learning_objects/1/untagging
# DELETE /v1/learning_objects/1/untagging.json
def untagging
taggable.tag_list.remove(params[:name])
if taggable.save
render json: @taggable, status: :ok
else
render json: @taggable.errors, status: :unprocessable_entity
end
end
protected
def taggable
raise NotImplementedError
end
def tag_params
params.require(:tag).permit(:name)
end
end
......@@ -53,6 +53,10 @@ class V1::CollectionsController < ApplicationController
set_collection
end
def taggable
set_collection
end
def sociable
set_collection
end
......@@ -65,5 +69,4 @@ class V1::CollectionsController < ApplicationController
def collection_params
params.require(:collection).permit(:name, :description, :owner_id, :owner_type, learning_objects: [])
end
end
......@@ -53,6 +53,10 @@ class V1::LearningObjectsController < ApplicationController
set_learning_object
end
def taggable
set_learning_object
end
# Use callbacks to share common setup or constraints between actions.
def set_learning_object
@learning_object ||= LearningObject.unscoped.find(params[:id])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment