Sha256: 0bf8660b903e791843e6096a1e9304cbcca7082ba9d2b77e6239f83db40a2750

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

require_dependency "todo_rails/application_controller"

module TodoRails
  class TasksController < ApplicationController
    before_action :set_task, only: [:show, :edit, :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
      head :no_content
    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.permit(:title, :completed, :row_order, :priority, :comment, :archieved)
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
todo_rails-0.1.7 app/controllers/todo_rails/tasks_controller.rb
todo_rails-0.1.6 app/controllers/todo_rails/tasks_controller.rb