Class: TodoRails::TasksController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- TodoRails::TasksController
- Defined in:
- app/controllers/todo_rails/tasks_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /tasks.
-
#destroy ⇒ Object
DELETE /tasks/1.
-
#index ⇒ Object
GET /tasks.
-
#show ⇒ Object
GET /tasks/1.
-
#update ⇒ Object
PATCH/PUT /tasks/1.
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
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 |
#destroy ⇒ Object
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 |
#index ⇒ Object
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 |
#show ⇒ Object
GET /tasks/1
14 15 16 |
# File 'app/controllers/todo_rails/tasks_controller.rb', line 14 def show render json: @task end |
#update ⇒ Object
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 |