From 7cb7146e7ef190f4dcc3fec2c74a615e034e77b3 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Wed, 4 Oct 2017 11:35:51 +0200 Subject: [PATCH] Implement update --- app/controllers/exercise_collections_controller.rb | 13 ++++++++++++- app/views/exercise_collections/_form.html.slim | 11 +++++++++++ app/views/exercise_collections/edit.html.slim | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 app/views/exercise_collections/_form.html.slim create mode 100644 app/views/exercise_collections/edit.html.slim diff --git a/app/controllers/exercise_collections_controller.rb b/app/controllers/exercise_collections_controller.rb index fb4e9ba2..a00f48fd 100644 --- a/app/controllers/exercise_collections_controller.rb +++ b/app/controllers/exercise_collections_controller.rb @@ -1,6 +1,7 @@ class ExerciseCollectionsController < ApplicationController + include CommonBehavior - before_action :set_exercise_collection, only: [:show] + before_action :set_exercise_collection, only: [:show, :edit, :update] def index @exercise_collections = ExerciseCollection.all.paginate(:page => params[:page]) @@ -10,6 +11,12 @@ class ExerciseCollectionsController < ApplicationController def show end + def edit + end + + def update + update_and_respond(object: @exercise_collection, params: exercise_collection_params) + end private @@ -21,4 +28,8 @@ class ExerciseCollectionsController < ApplicationController def authorize! authorize(@exercise_collection || @exercise_collections) end + + def exercise_collection_params + params[:exercise_collection].permit(:name, :exercise_ids) + end end diff --git a/app/views/exercise_collections/_form.html.slim b/app/views/exercise_collections/_form.html.slim new file mode 100644 index 00000000..a8ebf0b2 --- /dev/null +++ b/app/views/exercise_collections/_form.html.slim @@ -0,0 +1,11 @@ +- exercises = Exercise.all + += form_for(@exercise_collection, data: {exercises: exercises}, multipart: true) do |f| + = render('shared/form_errors', object: @exercise_collection) + .form-group + = f.label(:name) + = f.text_field(:name, class: 'form-control', required: true) + .form-group + = f.label(:exercises) + = f.collection_select(:exercise_ids, exercises, :id, :title, {}, {class: 'form-control', multiple: true}) + .actions = render('shared/submit_button', f: f, object: @exercise_collection) \ No newline at end of file diff --git a/app/views/exercise_collections/edit.html.slim b/app/views/exercise_collections/edit.html.slim new file mode 100644 index 00000000..4e864ab1 --- /dev/null +++ b/app/views/exercise_collections/edit.html.slim @@ -0,0 +1 @@ += render('form') \ No newline at end of file