Class: SubtasksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/subtasks_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /subtasks POST /subtasks.json


46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/subtasks_controller.rb', line 46

def create
  task = Task.find(params[:task_id])
  @subtask = task.subtasks.create(params[:subtask])

  respond_to do |format|
    if @subtask.save
      format.html { redirect_to [@subtask.task, @subtask], notice: 'Subtask was successfully created.' }
      format.json { render json: @subtask, status: :created, location: @subtask }
    else
      format.html { render action: "new" }
      format.json { render json: @subtask.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /subtasks/1 DELETE /subtasks/1.json


80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/subtasks_controller.rb', line 80

def destroy
  task = Task.find(params[:task_id])
  @subtask = task.subtasks.find(params[:id])
  @subtask.destroy

  respond_to do |format|
    format.html { redirect_to task_path(task) }
    format.json { head :no_content }
  end
end

#editObject

GET /subtasks/1/edit


39
40
41
42
# File 'app/controllers/subtasks_controller.rb', line 39

def edit
  task = Task.find(params[:task_id])
  @subtask = task.subtasks.find(params[:id])
end

#indexObject

GET /subtasks GET /subtasks.json


4
5
6
7
8
9
10
11
12
# File 'app/controllers/subtasks_controller.rb', line 4

def index
  task = Task.find(params[:task_id])
  @subtasks = task.subtasks

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @subtasks }
  end
end

#newObject

GET /subtasks/new GET /subtasks/new.json


28
29
30
31
32
33
34
35
36
# File 'app/controllers/subtasks_controller.rb', line 28

def new
  task = Task.find(params[:task_id])
  @subtask = task.subtasks.build

  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @subtask }
  end
end

#showObject

GET /subtasks/1 GET /subtasks/1.json


16
17
18
19
20
21
22
23
24
# File 'app/controllers/subtasks_controller.rb', line 16

def show
  task = Task.find(params[:task_id])
  @subtask = task.subtasks.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @subtask }
  end
end

#updateObject

PUT /subtasks/1 PUT /subtasks/1.json


63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/subtasks_controller.rb', line 63

def update
  task = Task.find(params[:task_id])
  @subtask = task.subtasks.find(params[:id])

  respond_to do |format|
    if @subtask.update_attributes(params[:subtask])
      format.html { redirect_to [@subtask.task, @subtask], notice: 'Subtask was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: "edit" }
      format.json { render json: @subtask.errors, status: :unprocessable_entity }
    end
  end
end