From e56bd9328da815c252da11bb736001b0fbf87589 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Tue, 6 Oct 2015 16:59:34 +0300 Subject: [PATCH] Randomize the talks --- app/controllers/application_controller.rb | 8 ++++++++ app/controllers/talk_preferences_controller.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 85da787..d00fd5e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,4 +9,12 @@ class ApplicationController < ActionController::Base # request.env['HTTP_X_FORWARDED_FOR'] || request.remote_ip end + + def sort_seed + if session[:random_sort_seed].present? + session[:random_sort_seed].to_i + else + session[:random_sort_seed] = Random.new_seed + end + end end diff --git a/app/controllers/talk_preferences_controller.rb b/app/controllers/talk_preferences_controller.rb index 8a9c48c..aed5e4e 100644 --- a/app/controllers/talk_preferences_controller.rb +++ b/app/controllers/talk_preferences_controller.rb @@ -1,6 +1,6 @@ class TalkPreferencesController < ApplicationController def index - @talks = Talk.all(params: {locale: I18n.locale}) + @talks = Talk.all(params: {locale: I18n.locale}).to_a.shuffle(random: Random.new(sort_seed)) end def show