-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraining_blocks_controller.rb
More file actions
43 lines (35 loc) · 1.27 KB
/
Copy pathtraining_blocks_controller.rb
File metadata and controls
43 lines (35 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class TrainingBlocksController < ApplicationController
before_action :set_training_block, only: %i[update destroy]
def index
@training_block = TrainingBlock.new
@training_blocks = current_user.training_blocks.ordered
end
def create
@training_block = current_user.training_blocks.new(training_block_params)
if @training_block.save
redirect_to training_blocks_path, notice: t("training_blocks.created")
else
@training_blocks = current_user.training_blocks.ordered
render :index, status: :unprocessable_entity
end
end
def update
if @training_block.update(training_block_params)
redirect_to training_blocks_path, notice: t("training_blocks.updated")
else
redirect_to training_blocks_path, alert: @training_block.errors.full_messages.to_sentence
end
end
def destroy
@training_block.destroy
redirect_to training_blocks_path, notice: t("training_blocks.destroyed")
end
private
# Правку и удаление пускаем только по своей библиотеке.
def set_training_block
@training_block = current_user.training_blocks.find(params[:id])
end
def training_block_params
params.require(:training_block).permit(:title, :description, :duration_minutes)
end
end