diff options
Diffstat (limited to 'app/controllers/application_controller.rb')
| -rw-r--r-- | app/controllers/application_controller.rb | 10 |
1 files changed, 10 insertions, 0 deletions
| 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 @@ | |||
| 1 | class ApplicationController < ActionController::Base | 1 | class ApplicationController < ActionController::Base |
| 2 | protect_from_forgery with: :exception | 2 | protect_from_forgery with: :exception |
| 3 | before_action :choose_random_song | ||
| 3 | 4 | ||
| 4 | private | 5 | private |
| 5 | 6 | ||
| 6 | def after_sign_out_path_for(resource) | 7 | def after_sign_out_path_for(resource) |
| 7 | new_session_path(resource) | 8 | new_session_path(resource) |
| 8 | end | 9 | end |
| 10 | |||
| 11 | def choose_random_song | ||
| 12 | ids = Scrobble.ids | ||
| 13 | if ids.empty? | ||
| 14 | @random_song = nil | ||
| 15 | else | ||
| 16 | @random_song = Scrobble.find(ids.sample) | ||
| 17 | end | ||
| 18 | end | ||
| 9 | end | 19 | end |
