-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathtasks_controller.rb
More file actions
104 lines (90 loc) · 2.43 KB
/
tasks_controller.rb
File metadata and controls
104 lines (90 loc) · 2.43 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
class TasksController < ApplicationController
before_action :set_task, only: %i[ show edit update destroy move ]
def move
if @task.notstarted?
@task.pending!
elsif @task.pending?
@task.complete!
elsif @task.complete?
@task.pending!
end
respond_to do |format|
format.js do
render template: "tasks/move.js.erb"
end
end
end
# GET /tasks or /tasks.json
def index
@tasks = current_user.tasks
end
# GET /tasks/1 or /tasks/1.json
def show
end
# GET /tasks/new
def new
@task = Task.new
end
# GET /tasks/1/edit
def edit
respond_to do |format|
format.html
format.js do
render template: "tasks/edit.js.erb"
end
end
end
# POST /tasks or /tasks.json
def create
@task = current_user.tasks.new(task_params)
respond_to do |format|
if @task.save
format.html { redirect_to task_url(@task), notice: "Task was successfully created." }
format.json { render :show, status: :created, location: @task }
format.js do
render template: "tasks/create.js.erb"
end
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @task.errors, status: :unprocessable_entity }
format.js
end
end
end
# PATCH/PUT /tasks/1 or /tasks/1.json
def update
respond_to do |format|
if @task.update(task_params)
format.html { redirect_to task_url(@task), notice: "Task was successfully updated." }
format.json { render :show, status: :ok, location: @task }
format.js do
render template: "tasks/update.js.erb"
end
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @task.errors, status: :unprocessable_entity }
format.js
end
end
end
# DELETE /tasks/1 or /tasks/1.json
def destroy
@task.destroy
respond_to do |format|
format.html { redirect_to tasks_url, notice: "Task was successfully destroyed." }
format.json { head :no_content }
format.js do
render template: "tasks/destroy.js.erb"
end
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_task
@task = Task.find(params[:id])
end
# Only allow a list of trusted parameters through.
def task_params
params.require(:task).permit(:body, :status)
end
end