Opti & reformat

master
E. Almqvist 3 years ago
parent 0248361e96
commit 05807cc520
  1. 13
      wesweb01/crud-music-2020/app.rb

@ -17,25 +17,24 @@ require "sqlite3"
#6. Skapa funktionalitet för att uppdatera artistinformation #6. Skapa funktionalitet för att uppdatera artistinformation
db_cache = SQLite3::Database.new("db/chinook-crud.db") # behöver inte skapa nya handlers varje gång vi ska "titta" i databasen
db_cache.results_as_hash = true
# Har därmed en "cache"
get "/" do get "/" do
slim(:start) slim(:start)
end end
get "/albums" do get "/albums" do
db = SQLite3::Database.new("db/chinook-crud.db") result = db_cache.execute("SELECT * FROM albums")
db.results_as_hash = true
result = db.execute("SELECT * FROM albums")
p result p result
slim( :"albums/index", locals: { albums: result } ) slim( :"albums/index", locals: { albums: result } )
end end
get "/albums/:id" do get "/albums/:id" do
id = params[:id].to_i id = params[:id].to_i
db = SQLite3::Database.new("db/chinook-crud.db") result = db_cache.execute("SELECT * FROM albums WHERE ArtistId = ?", id).first
db.results_as_hash = true slim( :"albums/show", locals: { result: result} )
result = db.execute("SELECT * FROM albums WHERE ArtistId = ?",id).first
slim(:"albums/show",locals:{result:result})
end end

Loading…
Cancel
Save