Cleaning in weeks controller

This commit is contained in:
Adrian Hinz 2019-05-16 10:31:02 +02:00
parent 5509f5d655
commit 8dfcbe28bc
1 changed files with 22 additions and 8 deletions

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
module Admin module Admin
# Kursy # Weeks
class WeeksController < ApplicationController class WeeksController < ApplicationController
before_action :set_object, only: %i[show edit update destroy] before_action :set_object, only: %i[show edit update destroy]
@ -27,17 +27,22 @@ module Admin
# POST /admin/weeks.json # POST /admin/weeks.json
def create def create
@week = Week.new(admin_week_params) @week = Week.new(admin_week_params)
@course = @week.course# .find(@week.course_id) @course = @week.course
params[:course_id] = @course.id params[:course_id] = @course.id
respond_to do |format| respond_to do |format|
if @week.save if @week.save
format.js { collection } 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 } format.json { render :show, status: :created, location: @week }
else else
format.js { render :new } format.js { render :new }
format.html { 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 end
end end
@ -48,12 +53,17 @@ module Admin
respond_to do |format| respond_to do |format|
if @week.update(admin_week_params) if @week.update(admin_week_params)
format.js { collection } 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 } format.json { render :show, status: :ok, location: @week }
else else
format.js { render :edit } format.js { render :edit }
format.html { 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 end
end end
@ -64,7 +74,10 @@ module Admin
@week.destroy @week.destroy
respond_to do |format| respond_to do |format|
format.js { collection } 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 } format.json { head :no_content }
end end
end end
@ -83,7 +96,8 @@ module Admin
@course = Course.find(params[:course_id]) @course = Course.find(params[:course_id])
end 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 def admin_week_params
params.require(:week).permit(:name, :description, :course_id) params.require(:week).permit(:name, :description, :course_id)
end end