local-llm-database/app.rb
2025-09-03 00:12:44 -05:00

69 lines
1.4 KiB
Ruby

# frozen_string_literal: true
require 'roda'
require 'tilt'
require 'tilt/erubi'
require_relative 'db'
require_relative 'models/assistant'
# Listing large language models (aka "Assistants")
class App < Roda
plugin :render, escape: true
plugin :sessions, secret: ENV.delete('APP_SESSION_SECRET')
plugin :all_verbs
route do |r|
r.root do
@page_title = 'Assistants List'
@subtitle = 'All Assistants in Database'
@assistants = Assistant.all
# renders index.erb inside layout.erb
view :index
end
r.on 'assistants' do
r.get 'new' do
@page_title = 'Create New Assistant'
@assistant = Assistant.new
view :edit
end
r.get ':id/edit' do |id|
@page_title = 'Edit Assistant'
@assistant = Assistant[id]
if @assistant.nil?
r.halt(404)
else
view :edit
end
end
r.post do
@assistant = Assistant.new(r.params)
if @assistant.save
r.redirect '/'
else
@page_title = 'Create New Assistant'
view :edit
end
end
r.put ':id' do |id|
@assistant = Assistant[id]
if @assistant && @assistant.update(r.params)
r.redirect '/'
else
r.halt(404)
end
end
r.delete ':id' do |id|
@assistant = Assistant[id]
@assistant.destroy if @assistant
r.redirect '/'
end
end
end
end