Files
doable/app/controllers/todos_controller.rb
Tarek Belkahia 40e832bfa2
Some checks are pending
CI / scan_ruby (push) Waiting to run
CI / scan_js (push) Waiting to run
CI / lint (push) Waiting to run
CI / test (push) Waiting to run
CI / system-test (push) Waiting to run
Add tailwind and styling for views
2025-10-27 16:09:04 +01:00

71 lines
1.8 KiB
Ruby

class TodosController < ApplicationController
before_action :set_todo, only: %i[ show edit update destroy ]
# GET /todos or /todos.json
def index
@todos = Todo.all
end
# GET /todos/1 or /todos/1.json
def show
end
# GET /todos/new
def new
@todo = Todo.new(project_id: params[:project_id])
end
# GET /todos/1/edit
def edit
end
# POST /todos or /todos.json
def create
@todo = Todo.new(todo_params)
respond_to do |format|
if @todo.save
format.html { redirect_to @todo, notice: "Todo was successfully created." }
format.json { render :show, status: :created, location: @todo }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @todo.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /todos/1 or /todos/1.json
def update
respond_to do |format|
if @todo.update(todo_params)
format.html { redirect_to @todo, notice: "Todo was successfully updated.", status: :see_other }
format.json { render :show, status: :ok, location: @todo }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @todo.errors, status: :unprocessable_entity }
end
end
end
# DELETE /todos/1 or /todos/1.json
def destroy
@todo.destroy!
respond_to do |format|
format.html { redirect_to todos_path, notice: "Todo was successfully destroyed.", status: :see_other }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_todo
@todo = Todo.find(params.expect(:id))
end
# Only allow a list of trusted parameters through.
def todo_params
params.expect(todo: [ :name, :description, :completed, :priority, :project_id ])
end
end