🧱 Moving to an API Based Architecture


🧹 Clean up Existing View

Remove the old Rails view:

rm app/views/tasks/index.html.erb


🔁 Update TasksController

Edit app/controllers/tasks_controller.rb:

class TasksController < ApplicationController
  def index
    tasks = Task.all
    render status: :ok, json: { tasks: }
  end
end

Note: { tasks: } is shorthand for { tasks: tasks } in Ruby 3.3.5+


⚛️ Create Home Controller

bundle exec rails generate controller Home

This creates:


🏠 Define Home#index

Edit app/controllers/home_controller.rb: