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

[WIP]fix learning object create

parent 3fc3844f
No related branches found
No related tags found
No related merge requests found
...@@ -4,9 +4,10 @@ class LearningObject::DraftBuilder ...@@ -4,9 +4,10 @@ class LearningObject::DraftBuilder
@draft = LearningObject.new(sanitize_params(params)) @draft = LearningObject.new(sanitize_params(params))
@draft.draft @draft.draft
# build topics # build tags
params[:topics].try(:each) do |t| #
@draft.topics << Topic.find(t) params[:tags].try(:each) do |t|
@draft.tags << Tag.find(t['id'])
end end
#build language #build language
...@@ -21,7 +22,7 @@ class LearningObject::DraftBuilder ...@@ -21,7 +22,7 @@ class LearningObject::DraftBuilder
def self.sanitize_params(args={}) def self.sanitize_params(args={})
_args = args.clone _args = args.clone
%w(topics language link).each do |arg| %w(tags language link).each do |arg|
_args.delete(arg) _args.delete(arg)
end end
metadata = [{'key' => 'dc.object.url', 'value' => args[:link]}] metadata = [{'key' => 'dc.object.url', 'value' => args[:link]}]
......
...@@ -35,10 +35,10 @@ class LearningObjectBuilder ...@@ -35,10 +35,10 @@ class LearningObjectBuilder
_params = params.clone _params = params.clone
_params.delete :link _params.delete :link
# build topics # build tags
_params[:topics] = [] _params[:tags] = []
params[:topics].try(:each) do |t| params[:tags].try(:each) do |t|
_params[:topics] << Topic.find(t) _params[:tags] << Tag.find(t['id'])
end end
#build language #build language
......
...@@ -68,6 +68,6 @@ class V1::CollectionsController < ApplicationController ...@@ -68,6 +68,6 @@ class V1::CollectionsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def collection_params def collection_params
params.require(:collection).permit(:name, :description, :owner_id, :owner_type, :privacy, :tag, learning_objects: []) params.require(:collection).permit(:name, :description, :owner_id, :owner_type, :privacy, tags: [], learning_objects: [])
end end
end end
...@@ -66,7 +66,7 @@ class V1::LearningObjectsController < ApplicationController ...@@ -66,7 +66,7 @@ class V1::LearningObjectsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def learning_object_params def learning_object_params
params[:learning_object].permit(:author, :name, :object_type_id, :description, :school_level, :language, :link, :tags) params[:learning_object].permit(:author, :name, :object_type_id, :description, :school_level, :language, :link, tags: [:id] )
end end
def authorize! def authorize!
......
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