From c3795830972a7d9912167acf5010793ca4f1b7f9 Mon Sep 17 00:00:00 2001 From: fosterfarrell9 <28628554+fosterfarrell9@users.noreply.github.com> Date: Wed, 9 Sep 2020 13:23:03 +0200 Subject: [PATCH] continue work on restful actions for tutorials --- app/controllers/tutorials_controller.rb | 6 ++++-- app/models/tutorial.rb | 6 ++++-- app/views/lectures/edit/_form.html.erb | 2 +- ...cise_classes.html.erb => _tutorials.html.erb} | 7 +++++-- app/views/tutorials/_form.html.erb | 16 ++++++++++------ app/views/tutorials/_row.html.erb | 7 +++++-- app/views/tutorials/create.coffee | 16 +++++++++++++++- app/views/tutorials/update.coffee | 16 +++++++++++++++- config/locales/de.yml | 8 +++++++- config/locales/en.yml | 7 ++++++- .../20200909104314_change_column_null_for.rb | 5 +++++ db/schema.rb | 4 ++-- 12 files changed, 79 insertions(+), 21 deletions(-) rename app/views/lectures/edit/{_exercise_classes.html.erb => _tutorials.html.erb} (90%) create mode 100644 db/migrate/20200909104314_change_column_null_for.rb diff --git a/app/controllers/tutorials_controller.rb b/app/controllers/tutorials_controller.rb index f840cd1a2..ab3d24c5a 100644 --- a/app/controllers/tutorials_controller.rb +++ b/app/controllers/tutorials_controller.rb @@ -1,7 +1,7 @@ # TutorialsController class TutorialsController < ApplicationController before_action :set_tutorial, only: [:edit, :destroy, :update, :cancel_edit] - authorize_resource + # authorize_resource def new @tutorial = Tutorial.new @@ -12,6 +12,7 @@ def new def create @tutorial = Tutorial.new(tutorial_params) @tutorial.save + @errors = @tutorial.errors end def edit @@ -19,6 +20,7 @@ def edit def update @tutorial.update(tutorial_params) + @errors = @tutorial.errors end def destroy @@ -32,7 +34,7 @@ def cancel_edit def set_tutorial @tutorial = Tutorial.find_by_id(params[:id]) - return if @tutorial.present? + return if @tutorial redirect_to :root, alert: I18n.t('controllers.no_tutorial') end diff --git a/app/models/tutorial.rb b/app/models/tutorial.rb index 0d79fdbac..7b4845321 100644 --- a/app/models/tutorial.rb +++ b/app/models/tutorial.rb @@ -1,5 +1,7 @@ # Tutorial model class Tutorial < ApplicationRecord - belongs_to :tutor, class_name: 'User', foreign_key: 'tutor_id' - belongs_to :lecture + belongs_to :tutor, class_name: 'User', foreign_key: 'tutor_id', optional: true + belongs_to :lecture, touch: true + + validates :title, uniqueness: { scope: [:lecture_id] } end diff --git a/app/views/lectures/edit/_form.html.erb b/app/views/lectures/edit/_form.html.erb index b3d659d92..f682a77b1 100644 --- a/app/views/lectures/edit/_form.html.erb +++ b/app/views/lectures/edit/_form.html.erb @@ -34,7 +34,7 @@ <%= render partial: 'lectures/edit/organizational_concept', locals: { lecture: lecture, inspection: inspection } %> - <%= render partial: 'lectures/edit/exercise_classes', + <%= render partial: 'lectures/edit/tutorials', locals: { lecture: lecture, inspection: inspection } %> <%= render partial: 'lectures/edit/announcements', diff --git a/app/views/lectures/edit/_exercise_classes.html.erb b/app/views/lectures/edit/_tutorials.html.erb similarity index 90% rename from app/views/lectures/edit/_exercise_classes.html.erb rename to app/views/lectures/edit/_tutorials.html.erb index e9614b40f..ae9fe1ef6 100644 --- a/app/views/lectures/edit/_exercise_classes.html.erb +++ b/app/views/lectures/edit/_tutorials.html.erb @@ -8,7 +8,7 @@