Skip to content

Instantly share code, notes, and snippets.

@traviskroberts
Last active August 29, 2015 13:56
Show Gist options
  • Save traviskroberts/8838030 to your computer and use it in GitHub Desktop.
Save traviskroberts/8838030 to your computer and use it in GitHub Desktop.
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
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
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
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