Implement update

This commit is contained in:
Maximilian Grundke
2017-10-04 11:35:51 +02:00
parent f0c0621b31
commit 7cb7146e7e
3 changed files with 24 additions and 1 deletions

View File

@ -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

View File

@ -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)

View File

@ -0,0 +1 @@
= render('form')