Some initial attempts at setting up delete and edit functions

This commit is contained in:
James Dinkel 2025-08-30 01:29:28 -04:00
parent 5c2466dfaf
commit 517bb5344d
3 changed files with 20 additions and 4 deletions

19
app.rb
View file

@ -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

View file

@ -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

View file

@ -25,6 +25,7 @@
<td><%= assistant.eval_rate || 'N/A' %></td>
<td><%= assistant.capabilities || 'N/A' %></td>
<td><%= assistant.created_at.strftime('%Y-%m-%d %H:%M') if assistant.created_at %></td>
</tr>
<% end %>
</tbody>