Git Product home page Git Product logo

randumb's People

Contributors

chewi avatar jdurand avatar mceachen avatar paulspringett avatar promisedlandt avatar schuetzm avatar spilliton avatar subosito avatar veader avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

randumb's Issues

wheight by created_at

Hi,
since created_at is not a directly considered numeric but still very numeric in nature, it would be great and probably not so hard to implement wheight random that work on date time.

could someone help me on that?

thank you very much

Does not respect default scopes

I noticed that when using the paranoia gem (which adds a default scope to exclude "soft deleted" records) that order_by_rand did not include the "where deleted_at is null".

It should respect that default scope and not blow it away

is it garanteed that there is no duplicate records

hello,

I like to use this gem to get random number of records that resulted from a query, like this:

            questions_of_quota= Quiz.where(:questions_category_id => questions_category_id)
            random_questions_of_quota= questions_of_quota.random(10)

Am I at the right place here ? and, will there be any duplicates in resulted records ?

thanks

Not working on Rails 3.2.8?

Hi,

Got gem in gemfile, and shows in bundle but when I use it in controller it returns no records. In console it throws an undefined method 'random' . ie User.all works User.random doesnt. On sqlite database, Rails 3.2.8

Randumb doesn't work in Rails 4

The current reason the build is failing. Struggling to get my dev environment working after a rvm update and ruby upgrade. Hopefully have this fixed soon :)

Random but unique/distinct?

If I have a set of 10 records, and ask for 5 random ones- can this choose 5 random ones that are all unique (no repeats)?

SQLite 3 - Statement Invalid - Missing Asterisk

Hi,

I'm trying to get your gem working, but it always throws an exception at me, that looks like this:

ActiveRecord::StatementInvalid (SQLite3::SQLException: near "FROM": syntax error: SELECT FROM "exercises" WHERE ("exercises"."id" IN (2)))

The problem is that is misses an asterisk * between SELECT and FROM. If i change the command to

SELECT * FROM "exercises" WHERE ("exercises"."id" IN (2))

and enter it in my SQLite-Database I get the record I wanted.

I would really like this thing to work because it could save me a lot of time.

Thanks in advance!

[feature] add seed parameter

I think most RDBMS random functions support the seed feature, I think this would be a useful new feature to be developed.

Andrea

License

Hi there!

Could you please add the license under which you'd like to distribute your gem? We would like to use it, but the client won't allow open source without the correct license.

Thnx

undefined method `shuffle!'

I'm using Rails 5

with method random_by_id_shuffle

undefined method `shuffle!' for #Person::ActiveRecord_Relation:0x000000062b3e68 Did you mean? shuffle

undefined method 'uniq_value'

I installed the gem, ran bundle install, and try to run the following code:

def index
@tracks = Track.random(5) #pick 5 random tracks, uses randumb gem
end

I get: undefined method `uniq_value' for #ActiveRecord::Relation:0x3f62d90

I double checked to see if randumb was installed by running 'bundle show randumb' and everything is good.

Thoughts?

NoMethodError - undefined method `reverse_merge' for 30:Fixnum

The line using randumb:

    users = User.where.not('users.avatar' => nil).order_by_rand(30)
$ rails --version
Rails 4.1.14.2

$ ruby --version
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
# ./Gemfile.lock
#...
    randumb (0.5.0)
      activerecord (>= 3.0.0)
      activesupport (>= 3.0.0)
      rake
#...

Trace:

NoMethodError - undefined method `reverse_merge' for 30:Fixnum:
  randumb (0.5.0) lib/randumb/relation.rb:79:in `build_order_scope'
  randumb (0.5.0) lib/randumb/relation.rb:67:in `order_by_rand'
  app/controllers/api/user_wishes_controller.rb:60:in `index'
  actionpack (4.1.14.2) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.1.14.2) lib/abstract_controller/base.rb:189:in `process_action'
  actionpack (4.1.14.2) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.1.14.2) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.1.14.2) lib/active_support/callbacks.rb:113:in `call'
  activesupport (4.1.14.2) lib/active_support/callbacks.rb:552:in `block (2 levels) in compile'
  activesupport (4.1.14.2) lib/active_support/callbacks.rb:502:in `call'
  activesupport (4.1.14.2) lib/active_support/callbacks.rb:86:in `run_callbacks'
  actionpack (4.1.14.2) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.1.14.2) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.1.14.2) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (4.1.14.2) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.1.14.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.1.14.2) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.1.14.2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.1.14.2) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.1.14.2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.1.14.2) lib/abstract_controller/base.rb:136:in `process'
  actionview (4.1.14.2) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.1.14.2) lib/action_controller/metal.rb:196:in `dispatch'
  actionpack (4.1.14.2) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.1.14.2) lib/action_controller/metal.rb:232:in `block in action'
  actionpack (4.1.14.2) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
  actionpack (4.1.14.2) lib/action_dispatch/routing/route_set.rb:48:in `call'
  actionpack (4.1.14.2) lib/action_dispatch/journey/router.rb:73:in `block in call'
  actionpack (4.1.14.2) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.1.14.2) lib/action_dispatch/routing/route_set.rb:690:in `call'
  bullet (5.0.0) lib/bullet/rack.rb:12:in `call'
  warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  rack (1.5.5) lib/rack/etag.rb:23:in `call'
  rack (1.5.5) lib/rack/conditionalget.rb:25:in `call'
  rack (1.5.5) lib/rack/head.rb:11:in `call'
  actionpack (4.1.14.2) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.1.14.2) lib/action_dispatch/middleware/flash.rb:254:in `call'
  rack (1.5.5) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.5) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.1.14.2) lib/action_dispatch/middleware/cookies.rb:562:in `call'
  activerecord (4.1.14.2) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.1.14.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
  activerecord (4.1.14.2) lib/active_record/migration.rb:380:in `call'
  actionpack (4.1.14.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.1.14.2) lib/active_support/callbacks.rb:82:in `run_callbacks'
  actionpack (4.1.14.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.1.14.2) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.1.14.2) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  bugsnag (3.0.0) lib/bugsnag/rack.rb:33:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  actionpack (4.1.14.2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.1.14.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.1.14.2) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.14.2) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.1.14.2) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.1.14.2) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.14.2) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.14.2) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.1.14.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.5) lib/rack/runtime.rb:17:in `call'
  rack-timeout (0.3.2) lib/rack/timeout/core.rb:125:in `block in call'
  rack-timeout (0.3.2) lib/rack/timeout/support/timeout.rb:19:in `timeout'
  rack-timeout (0.3.2) lib/rack/timeout/core.rb:124:in `call'
  activesupport (4.1.14.2) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
  rack (1.5.5) lib/rack/lock.rb:17:in `call'
  actionpack (4.1.14.2) lib/action_dispatch/middleware/static.rb:84:in `call'
  font_assets (0.1.12) lib/font_assets/middleware.rb:29:in `call'
  rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
  railties (4.1.14.2) lib/rails/engine.rb:514:in `call'
  railties (4.1.14.2) lib/rails/application.rb:144:in `call'
  /Users/jottr/Library/Application Support/Pow/Versions/0.5.0/node_modules/nack/lib/nack/server.rb:155:in `handle'
  /Users/jottr/Library/Application Support/Pow/Versions/0.5.0/node_modules/nack/lib/nack/server.rb:109:in `rescue in block (2 levels) in start'
  /Users/jottr/Library/Application Support/Pow/Versions/0.5.0/node_modules/nack/lib/nack/server.rb:106:in `block (2 levels) in start'
  /Users/jottr/Library/Application Support/Pow/Versions/0.5.0/node_modules/nack/lib/nack/server.rb:96:in `block in start'
  /Users/jottr/Library/Application Support/Pow/Versions/0.5.0/node_modules/nack/lib/nack/server.rb:76:in `start'
  /Users/jottr/Library/Application Support/Pow/Versions/0.5.0/node_modules/nack/lib/nack/server.rb:12:in `run'
  /Users/jottr/Library/Application Support/Pow/Versions/0.5.0/node_modules/nack/bin/nack_worker:4:in `<main>'



order by error.

ActiveRecord::StatementInvalid (ActiveRecord::JDBCError: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
Position: 250: SELECT DISTINCT "categorizations".* FROM "categorizations" LEFT OUTER JOIN "classifications" ON "classifications"."id" = "categorizations"."classification_id" WHERE "categorizations"."invited" = 'f' AND "categorizations"."category_id" = 2 ORDER BY RANDOM() LIMIT 5)

That's a new error for me, I didn't have this error before.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.