local-llm-database/app.rb

60 lines
1.3 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.post do
@assistant = Assistant.new(r.params)
if @assistant.save
r.redirect '/' # change to just r.redirect when get a host.org/assistants page up
else
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