Class: Ld4lVirtualCollection::CollectionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ld4l_virtual_collection/collections_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /collections



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/ld4l_virtual_collection/collections_controller.rb', line 36

def create
  # puts("*** Entering CTRL: create collection")
  @collection = Collection.new(collection_params)
  persisted = false
  error_msg = ''
  begin
    persisted = LD4L::OreRDF::PersistAggregation.call(@collection)
  rescue ArgumentError
    # TODO should check that error message from ArgumentError is that Title is missing.
    error_msg = "Title is required."
  end
  if persisted == true
    flash[:notice] = 'Collection was successfully created.'
    redirect_to my_virtual_collection_path(@collection.id.to_s)
  else
    flash[:error] = "Collection not created.  #{error_msg}"
    redirect_to my_virtual_collections_path
  end
end

#destroyObject

DELETE /collections/1



79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/ld4l_virtual_collection/collections_controller.rb', line 79

def destroy
  # puts("*** Entering CTRL: destroy collection")
  if LD4L::OreRDF::DestroyAggregation.call(@collection) == true
    redirect_to my_virtual_collections_path, notice: 'Collection was successfully destroyed.'
  else
    # TODO Should it redirect to edit???  OR list???  OR  where???
    # TODO How to add error message about what failed to be destroyed???
    render :edit
  end
end

#editObject

GET /collections/1/edit



31
32
33
# File 'app/controllers/ld4l_virtual_collection/collections_controller.rb', line 31

def edit
  # puts("*** Entering CTRL: edit")
end

#indexObject

GET /collections



15
16
17
# File 'app/controllers/ld4l_virtual_collection/collections_controller.rb', line 15

def index
  @collections = Collection.all
end

#newObject

GET /collections/new



25
26
27
28
# File 'app/controllers/ld4l_virtual_collection/collections_controller.rb', line 25

def new
  # puts("*** Entering CTRL: new collection")
  @collection = Collection.new
end

#showObject

GET /collections/1



20
21
22
# File 'app/controllers/ld4l_virtual_collection/collections_controller.rb', line 20

def show
  # puts("*** Entering CTRL: show collection")
end

#updateObject

PATCH/PUT /collections/1



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/ld4l_virtual_collection/collections_controller.rb', line 57

def update
  # puts("*** Entering CTRL: update collection")
  @collection = Collection.update(collection_params)
  persisted = false
  error_msg = ''
  begin
    # TODO -- should update check that proxies persisted as well???
    persisted = LD4L::OreRDF::PersistAggregation.call(@collection)
  rescue ArgumentError
    # TODO should check that error message from ArgumentError is that Title is missing.
    error_msg = "Title is required."
  end
  if persisted == true
    flash[:notice] = 'Collection was successfully updated.'
    redirect_to my_virtual_collection_path(@collection.id.to_s)
  else
    flash[:error] = "Collection not updated.  #{error_msg}"
    redirect_to my_virtual_collections_path
  end
end