/
tasks_controller.rb
52 lines (39 loc) · 1.04 KB
/
tasks_controller.rb
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
class TasksController < ApplicationController
def index
@todo = Task.where(:done => false)
@task = Task.new
@lists = List.all
@list = List.new
respond_to do |format|
format.html
end
end
def create
@list = List.find(params[:list_id])
@task = @list.tasks.new(params[:task])
if @task.save
flash[:notice] = "Your task was created."
else
flash[:alert] = "There was an error creating your task."
end
redirect_to(list_tasks_url(@list))
end
def update
@list = List.find(params[:list_id])
@task = @list.tasks.find(params[:id])
respond_to do |format|
if @task.update_attributes(params[:task])
format.html { redirect_to( list_tasks_url(@list), :notice => 'Task was successfully updated.') }
else
format.html { render :action => "edit" }
end
end
end
def destroy
@task = Task.find(params[:id])
@task.destroy
respond_to do |format|
format.html { redirect_to(list_tasks_url(@list)) }
end
end
end