Class: TodoRails::TasksController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#set_settings

Instance Method Details

#createObject

POST /tasks



19
20
21
22
23
24
25
26
27
# File 'app/controllers/todo_rails/tasks_controller.rb', line 19

def create
  @task = Task.new(task_params)

  if @task.save
    render json: @task, status: :created, location: @task
  else
    render json: @task.errors, status: :unprocessable_entity
  end
end

#destroyObject

DELETE /tasks/1



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

def destroy
  @task.destroy
  head :no_content
end

#indexObject

GET /tasks



8
9
10
11
# File 'app/controllers/todo_rails/tasks_controller.rb', line 8

def index
  @tasks = Task.all
  render json: @tasks
end

#showObject

GET /tasks/1



14
15
16
# File 'app/controllers/todo_rails/tasks_controller.rb', line 14

def show
  render json: @task
end

#updateObject

PATCH/PUT /tasks/1



30
31
32
33
34
35
36
# File 'app/controllers/todo_rails/tasks_controller.rb', line 30

def update
  if @task.update(task_params)
    render json: @task
  else
    render json: @task.errors, status: :unprocessable_entity
  end
end