Skip to content

Instantly share code, notes, and snippets.

@kpumuk
Forked from mdarby/gist:43082
Created January 28, 2009 19:28

Revisions

  1. kpumuk revised this gist Jan 28, 2009. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -5,11 +5,9 @@
    class ActiveRecord::Base

    def self.random
    begin
    find(rand(count))
    rescue ActiveRecord::RecordNotFound
    self.random
    end
    find(rand(count))
    rescue ActiveRecord::RecordNotFound
    retry
    end

    end
  2. @mdarby mdarby created this gist Jan 4, 2009.
    15 changes: 15 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    # Usage:
    # >> User.random
    # => #<User login: ...

    class ActiveRecord::Base

    def self.random
    begin
    find(rand(count))
    rescue ActiveRecord::RecordNotFound
    self.random
    end
    end

    end