From 4a9bf38ef61b39e482458ba56cd1e6fea379b4d7 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 21 Nov 2025 21:01:50 -0500 Subject: Added "listening to" box in sidebar --- app/assets/stylesheets/main/layout.scss | 11 +++++++++++ app/controllers/application_controller.rb | 10 ++++++++++ app/models/scrobble.rb | 2 ++ app/views/layouts/application.html.haml | 10 ++++++++++ 4 files changed, 33 insertions(+) create mode 100644 app/models/scrobble.rb (limited to 'app') diff --git a/app/assets/stylesheets/main/layout.scss b/app/assets/stylesheets/main/layout.scss index ef31ada..d5fe7a7 100644 --- a/app/assets/stylesheets/main/layout.scss +++ b/app/assets/stylesheets/main/layout.scss @@ -228,3 +228,14 @@ h2.centered { text-decoration: none; } } + +#scrobble-box { + img { + margin: 0 auto; + display: block; + } + + p { + text-align: center; + } +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0174cae..ad46fb9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,9 +1,19 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception + before_action :choose_random_song private def after_sign_out_path_for(resource) new_session_path(resource) end + + def choose_random_song + ids = Scrobble.ids + if ids.empty? + @random_song = nil + else + @random_song = Scrobble.find(ids.sample) + end + end end diff --git a/app/models/scrobble.rb b/app/models/scrobble.rb new file mode 100644 index 0000000..f527612 --- /dev/null +++ b/app/models/scrobble.rb @@ -0,0 +1,2 @@ +class Scrobble < ApplicationRecord +end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 1d0bea3..6bc7041 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -73,6 +73,16 @@ %li = image_tag "feed.png" = link_to "Atom feed", blogs_url(format: :atom) + - unless @random_song.nil? + .sidebar-module#scrobble-box + .bubble.rounded + %h2 Listening to + = image_tag @random_song.image, width: "174px" + %p + %strong= @random_song.title + by + = @random_song.artist + %p= @random_song.album .sidebar-module .bubble.rounded %h2 Meta -- cgit 1.4.1