From 8dfcbe28bca02251a4daedd66606b2ca1f012202 Mon Sep 17 00:00:00 2001 From: Adrian Hinz Date: Thu, 16 May 2019 10:31:02 +0200 Subject: [PATCH] Cleaning in weeks controller --- app/controllers/admin/weeks_controller.rb | 30 +++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/weeks_controller.rb b/app/controllers/admin/weeks_controller.rb index 5962118..c2551b7 100644 --- a/app/controllers/admin/weeks_controller.rb +++ b/app/controllers/admin/weeks_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Admin - # Kursy + # Weeks class WeeksController < ApplicationController before_action :set_object, only: %i[show edit update destroy] @@ -27,17 +27,22 @@ module Admin # POST /admin/weeks.json def create @week = Week.new(admin_week_params) - @course = @week.course# .find(@week.course_id) + @course = @week.course params[:course_id] = @course.id respond_to do |format| if @week.save format.js { collection } - format.html { redirect_to [:admin, @week], notice: 'Week was successfully created.' } + format.html do + redirect_to [:admin, @week], + notice: 'Week was successfully created.' + end format.json { render :show, status: :created, location: @week } else format.js { render :new } format.html { render :new } - format.json { render json: @week.errors, status: :unprocessable_entity } + format.json do + render json: @week.errors, status: :unprocessable_entity + end end end end @@ -48,12 +53,17 @@ module Admin respond_to do |format| if @week.update(admin_week_params) format.js { collection } - format.html { redirect_to [:admin, @week], notice: 'Week was successfully updated.' } + format.html do + redirect_to [:admin, @week], + notice: 'Week was successfully updated.' + end format.json { render :show, status: :ok, location: @week } else format.js { render :edit } format.html { render :edit } - format.json { render json: @week.errors, status: :unprocessable_entity } + format.json do + render json: @week.errors, status: :unprocessable_entity + end end end end @@ -64,7 +74,10 @@ module Admin @week.destroy respond_to do |format| format.js { collection } - format.html { redirect_to admin_weeks_url, notice: 'Week was successfully destroyed.' } + format.html do + redirect_to admin_weeks_url, + notice: 'Week was successfully destroyed.' + end format.json { head :no_content } end end @@ -83,7 +96,8 @@ module Admin @course = Course.find(params[:course_id]) end - # 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 admin_week_params params.require(:week).permit(:name, :description, :course_id) end