From 517bb5344d8941991c2be1d8998cd9b7bcb0e574 Mon Sep 17 00:00:00 2001 From: James Dinkel Date: Sat, 30 Aug 2025 01:29:28 -0400 Subject: [PATCH] Some initial attempts at setting up delete and edit functions --- app.rb | 19 +++++++++++++++++++ models/assistant.rb | 4 ---- views/index.erb | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app.rb b/app.rb index 096b0b4..186bdd4 100644 --- a/app.rb +++ b/app.rb @@ -11,6 +11,7 @@ require_relative 'models/assistant' class App < Roda plugin :render, escape: true plugin :sessions, secret: ENV.delete('APP_SESSION_SECRET') + plugin :all_verbs route do |r| r.root do @@ -27,6 +28,7 @@ class App < Roda @assistant = Assistant.new view :edit end + r.post do @assistant = Assistant.new(r.params) if @assistant.save @@ -35,6 +37,23 @@ class App < Roda r.halt(404) end end + + # Delete route + r.delete 'delete/:id' do + assistant = Assistant.find(params[:id]) + if assistant + assistant.destroy + r.redirect '/' + else + r.halt(404) + end + end + + # View route + r.get 'view', :id do + @assistant = Assistant.find(params[:id]) + "#{@assistant}" + end end end end diff --git a/models/assistant.rb b/models/assistant.rb index 1101aae..b842e05 100644 --- a/models/assistant.rb +++ b/models/assistant.rb @@ -17,8 +17,4 @@ class Assistant < Sequel::Model def self.find_by_name(name) where(name: name).first end - - def self.active - where(active: true) - end end diff --git a/views/index.erb b/views/index.erb index 8bd9f7c..2ba8ec4 100644 --- a/views/index.erb +++ b/views/index.erb @@ -25,6 +25,7 @@ <%= assistant.eval_rate || 'N/A' %> <%= assistant.capabilities || 'N/A' %> <%= assistant.created_at.strftime('%Y-%m-%d %H:%M') if assistant.created_at %> + <% end %>