Last active
August 29, 2015 13:56
-
-
Save traviskroberts/8838030 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
before_filter :set_rand_cookie | |
private | |
def set_rand_cookie | |
return if cookies[:rand_seed].present? | |
cookies[:rand_seed] = {value: rand(100), expires: Time.now + 900} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
before_filter :set_rand_cookie | |
private | |
def set_rand_cookie | |
return if cookies[:rand_seed].present? | |
cookies[:rand_seed] = {value: rand, expires: Time.now + 900} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MembersController < ApplicationController | |
def index | |
seed_val = Member.connection.quote(cookies[:rand_seed]) | |
@members = Member.order("RAND(#{seed_val})").page(params[:page]).per(15) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MembersController < ApplicationController | |
def index | |
seed_val = Member.connection.quote(cookies[:rand_seed]) | |
Member.connection.execute("select setseed(#{seed_val})") | |
@members = Member.order('random()').page(params[:page]).per(15) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment