Cleaning in weeks controller
This commit is contained in:
parent
5509f5d655
commit
8dfcbe28bc
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue