Created
July 11, 2016 01:09
-
-
Save jhwhite/3e812bb708c6c6a8a0e965a08548ef50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #route | |
| get 'tasks/todos-total', to: 'tasks#total_todos' | |
| #tasks_controller | |
| class TasksController < ApplicationController | |
| before_action :set_task, only: [:show, :update, :destroy] | |
| # GET /tasks | |
| def index | |
| @tasks = Task.all | |
| render json: @tasks | |
| end | |
| # GET /tasks/1 | |
| def show | |
| render json: @task | |
| end | |
| # POST /tasks | |
| 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 | |
| # PATCH/PUT /tasks/1 | |
| def update | |
| if @task.update(task_params) | |
| render json: @task | |
| else | |
| render json: @task.errors, status: :unprocessable_entity | |
| end | |
| end | |
| # DELETE /tasks/1 | |
| def destroy | |
| @task.destroy | |
| end | |
| def total_todos | |
| render json: Task.count | |
| end | |
| private | |
| # Use callbacks to share common setup or constraints between actions. | |
| def set_task | |
| @task = Task.find(params[:id]) | |
| end | |
| # Only allow a trusted parameter "white list" through. | |
| def task_params | |
| params.require(:task).permit(:title, :firstname, :lastname, :completed, :order) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment