Revert "Revert "Removed duplicate DB object""

This reverts commit 4bf4d8f73e.
master
E. Almqvist 3 years ago
parent 4bf4d8f73e
commit c8878357b2
  1. 12
      wesweb01/crud-music-2020/app.rb
  2. 1
      wesweb01/crud-music-2020/views/albums/show.slim

@ -18,13 +18,16 @@ require "sqlite3"
#6. Skapa funktionalitet för att uppdatera artistinformation
db = SQLite3::Database.new("db/chinook-crud.db")
db.results_as_hash = true
get "/" do
slim(:start)
end
get "/albums" do
db = SQLite3::Database.new("db/chinook-crud.db")
db.results_as_hash = true
result = db.execute("SELECT * FROM albums")
p result
slim(:"albums/index", locals: {albums: result})
@ -32,10 +35,9 @@ end
get "/albums/:id" do
id = params[:id].to_i
db = SQLite3::Database.new("db/chinook-crud.db")
db.results_as_hash = true
result = db.execute("SELECT * FROM albums WHERE ArtistId = ?", id).first
slim(:"albums/show",locals: {result: result})
artist = db.execute("SELECT Name FROM artists WHERE ArtistId IN (SELECT ArtistId FROM Albums WHERE AlbumId = ?)", id).first
slim(:"albums/show",locals: {result: result, artist: artist})
end

@ -2,3 +2,4 @@ h1 = result
p Albumet som du har sökt efter heter #{result["Title"]}.
p Artisten som du har sökt efter heter #{result["ArtistId"]}.
p Artisten som du har sökt efter heter #{artist["Name"]}.

Loading…
Cancel
Save