Class: TasksController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /tasks POST /tasks.json


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/tasks_controller.rb', line 53

def create
  if current_user == nil
    @task = Task.new(params[:task])
  else
    @task = current_user.tasks.new(params[:task])
  end

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

#destroyObject

DELETE /tasks/1 DELETE /tasks/1.json


89
90
91
92
93
94
95
96
97
# File 'app/controllers/tasks_controller.rb', line 89

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

  respond_to do |format|
    format.html { redirect_to tasks_url }
    format.json { head :no_content }
  end
end

#editObject

GET /tasks/1/edit


47
48
49
# File 'app/controllers/tasks_controller.rb', line 47

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

#indexObject

GET /tasks GET /tasks.json


11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/tasks_controller.rb', line 11

def index
  if current_user == nil
    @tasks = nil
  else
    @tasks = current_user.tasks
  end

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

#newObject

GET /tasks/new GET /tasks/new.json


37
38
39
40
41
42
43
44
# File 'app/controllers/tasks_controller.rb', line 37

def new
  @task = Task.new

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

#showObject

GET /tasks/1 GET /tasks/1.json


26
27
28
29
30
31
32
33
# File 'app/controllers/tasks_controller.rb', line 26

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

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

#updateObject

PUT /tasks/1 PUT /tasks/1.json


73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/tasks_controller.rb', line 73

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

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

#welcomeObject


2
3
4
5
6
7
8
# File 'app/controllers/tasks_controller.rb', line 2

def welcome
  if current_user != nil
    redirect_to tasks_path
  else
    render :file => 'public/index.html.erb'
  end
end