twitter / activerecord-reputation-system Goto Github PK
View Code? Open in Web Editor NEWAn Active Record Reputation System for Rails
License: Apache License 2.0
An Active Record Reputation System for Rails
License: Apache License 2.0
Running @answer.evaluators_for(:answer_reputation) in console
invokes
ReputationSystem::Evaluation Load (0.6ms) SELECT "rs_evaluations".* FROM "rs_evaluations" WHERE "rs_evaluations"."target_id" = 131 AND "rs_evaluations"."target_type" = 'Answer' AND "rs_evaluations"."reputation_name" = 'answer_reputation'
It returns Evaluations not evaluators (in my case 'users') as opposed to the wiki.
I am trying to have AdminUsers able to vote on Items. My two models are configured as follows:
Item.rb
has_reputation :votes, source: :admin_user, aggregated_by: :sum
AdminUser.rb
has_reputation :votes, source: {reputation: :votes, of: :items}, aggregated_by: :sum
Everything works unless I include the association in AdminUser.rb which raises the following error. The vote still gets saved because when I refresh the page the vote appears fine. Any guidance appreciated. Thanks!!
NameError in Admin::ItemsController#vote
undefined local variable or method `admin_user' for #<Item:0x007f9d0d370698>
Rails.root: /Users/robin/SkyDrive/Github/Ruby/Example/
Application Trace | Framework Trace | Full Trace
/Users/chourobin/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-1.4.0/lib/reputation_system/base.rb:25:in `instance_eval'
/Users/chourobin/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/attribute_methods.rb:149:in `method_missing'
(eval):1:in `get_attributes_of'
/Users/chourobin/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-1.4.0/lib/reputation_system/base.rb:25:in `instance_eval'
/Users/chourobin/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-1.4.0/lib/reputation_system/base.rb:25:in `get_attributes_of'
/Users/chourobin/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-1.4.0/lib/models/rs_reputation.rb:130:in `block in propagate_updated_reputation_value'
/Users/chourobin/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-1.4.0/lib/models/rs_reputation.rb:129:in `each'
/Users/chourobin/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-1.4.0/lib/models/rs_reputation.rb:129:in `propagate_updated_reputation_value'
/Users/chourobin/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-1.4.0/lib/models/rs_reputation.rb:90:in `update_reputation_value_with_updated_source'
/Users/chourobin/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-1.4.0/lib/reputation_system/evaluation.rb:52:in `update_evaluation'
/Users/chourobin/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-1.4.0/lib/reputation_system/evaluation.rb:118:in `change_evaluation_value_by'
/Users/chourobin/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-1.4.0/lib/reputation_system/evaluation.rb:75:in `increase_evaluation'
app/admin/items.rb:59:in `block (2 levels) in <top (required)>'
Rails Server log
Processing by Admin::ItemsController#vote as HTML
Parameters: {"authenticity_token"=>"/ikghElE4+CCZ3IVVmN7f0+0e/DHMq1ICXpxpeeQOi8=", "type"=>"up", "place_id"=>"1", "id"=>"1"}
AdminUser Load (0.4ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = 1 LIMIT 1
Item Load (0.2ms) SELECT "items".* FROM "items" WHERE "items"."id" = $1 LIMIT 1 [["id", "1"]]
RSEvaluation Load (0.5ms) SELECT "rs_evaluations".* FROM "rs_evaluations" WHERE (("rs_evaluations"."reputation_name" = 'votes' AND "rs_evaluations"."source_id" = 1 AND "rs_evaluations"."source_type" = 'AdminUser' AND "rs_evaluations"."target_id" = 1 AND "rs_evaluations"."target_type" = 'Item')) LIMIT 1
CACHE (0.0ms) SELECT "rs_evaluations".* FROM "rs_evaluations" WHERE (("rs_evaluations"."reputation_name" = 'votes' AND "rs_evaluations"."source_id" = 1 AND "rs_evaluations"."source_type" = 'AdminUser' AND "rs_evaluations"."target_id" = 1 AND "rs_evaluations"."target_type" = 'Item')) LIMIT 1
(0.1ms) BEGIN
RSEvaluation Exists (0.3ms) SELECT 1 AS one FROM "rs_evaluations" WHERE ("rs_evaluations"."source_id" = 1 AND "rs_evaluations"."id" != 7 AND "rs_evaluations"."reputation_name" = 'votes' AND "rs_evaluations"."source_type" = 'AdminUser' AND "rs_evaluations"."target_id" = 1 AND "rs_evaluations"."target_type" = 'Item') LIMIT 1
(0.4ms) UPDATE "rs_evaluations" SET "value" = 0.0, "updated_at" = '2012-09-11 21:46:33.428244' WHERE "rs_evaluations"."id" = 7
(1.0ms) COMMIT
RSReputation Load (0.3ms) SELECT "rs_reputations".* FROM "rs_reputations" WHERE (("rs_reputations"."reputation_name" = 'votes' AND "rs_reputations"."target_id" = 1 AND "rs_reputations"."target_type" = 'Item')) LIMIT 1
(0.4ms) SELECT COUNT(*) FROM "rs_reputation_messages" WHERE "rs_reputation_messages"."receiver_id" = 1
(0.2ms) BEGIN
RSReputation Exists (0.4ms) SELECT 1 AS one FROM "rs_reputations" WHERE ("rs_reputations"."reputation_name" = 'votes' AND "rs_reputations"."id" != 1 AND "rs_reputations"."target_id" = 1 AND "rs_reputations"."target_type" = 'Item') LIMIT 1
(0.3ms) UPDATE "rs_reputations" SET "value" = 11.0, "updated_at" = '2012-09-11 21:46:33.436129' WHERE "rs_reputations"."id" = 1
(1.4ms) COMMIT
Item Load (0.3ms) SELECT "items".* FROM "items" WHERE "items"."id" = 1 LIMIT 1
Completed 500 Internal Server Error in 121ms
NameError (undefined local variable or method `admin_user' for #<Item:0x007f9d0d370698>):
app/admin/items.rb:59:in `block (2 levels) in <top (required)>'
Hi ! I'm using this gem, thank you !
Is it possible to do any action automatically before or after evaluation ? Like before_save or after_validation for an ActiveRecord.
Thank you
reptuation_for
should be reputation_for
:)
ArgumentError - question_reputation is not defined for NilClass:
(gem) activerecord-reputation-system-2.0.2/lib/reputation_system/network.rbin get_scoped_reputation_name'
(gem) activerecord-reputation-system-2.0.2/lib/reputation_system/network.rb:161:inget_scoped_reputation_name_from_source_def_and_target'
(gem) activerecord-reputation-system-2.0.2/lib/reputation_system/network.rb:111:in block in get_weight_of_source_from_reputation_name_of_target'
(gem) activerecord-reputation-system-2.0.2/lib/reputation_system/network.rb:110:inget_weight_of_source_from_reputation_name_of_target'
(gem) activerecord-reputation-system-2.0.2/lib/reputation_system/models/reputation.rb:150:in send_reputation_message_to_receiver'
(gem) activerecord-reputation-system-2.0.2/lib/reputation_system/models/reputation.rb:140:inblock (2 levels) in propagate_updated_reputation_value'
(gem) activerecord-reputation-system-2.0.2/lib/reputation_system/models/reputation.rb:138:in block in propagate_updated_reputation_value'
(gem) activerecord-reputation-system-2.0.2/lib/reputation_system/models/reputation.rb:136:inpropagate_updated_reputation_value'
(gem) activerecord-reputation-system-2.0.2/lib/reputation_system/models/reputation.rb:97:in update_reputation_value_with_updated_source'
(gem) activerecord-reputation-system-2.0.2/lib/reputation_system/evaluation_methods.rb:125:indelete_evaluation_without_validation'
(gem) activerecord-reputation-system-2.0.2/lib/reputation_system/evaluation_methods.rb:81:in delete_evaluation'
app/models/post.rb:82:inunvote'
app/controllers/posts_controller.rb:31:in unvote'
(gem) actionpack-3.2.12/lib/action_controller/metal/implicit_render.rb:4:insend_action'
(gem) actionpack-3.2.12/lib/abstract_controller/base.rb:167:in process_action'
(gem) actionpack-3.2.12/lib/action_controller/metal/rendering.rb:10:inprocess_action'
(gem) actionpack-3.2.12/lib/abstract_controller/callbacks.rb:18:in block in process_action'
(gem) activesupport-3.2.12/lib/active_support/callbacks.rb:436:in_run__2222011682516618363__process_action__4054774554349963175__callbacks'
(gem) activesupport-3.2.12/lib/active_support/callbacks.rb:405:in __run_callback'
(gem) activesupport-3.2.12/lib/active_support/callbacks.rb:385:in_run_process_action_callbacks'
(gem) activesupport-3.2.12/lib/active_support/callbacks.rb:81:in run_callbacks'
(gem) actionpack-3.2.12/lib/abstract_controller/callbacks.rb:17:inprocess_action'
(gem) actionpack-3.2.12/lib/action_controller/metal/rescue.rb:29:in process_action'
(gem) actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:30:inblock in process_action'
(gem) activesupport-3.2.12/lib/active_support/notifications.rb:123:in block in instrument'
(gem) activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:ininstrument'
(gem) activesupport-3.2.12/lib/active_support/notifications.rb:123:in instrument'
(gem) actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:29:inprocess_action'
(gem) actionpack-3.2.12/lib/action_controller/metal/params_wrapper.rb:207:in process_action'
(gem) activerecord-3.2.12/lib/active_record/railties/controller_runtime.rb:18:inprocess_action'
(gem) actionpack-3.2.12/lib/abstract_controller/base.rb:121:in process'
(gem) actionpack-3.2.12/lib/abstract_controller/rendering.rb:45:inprocess'
(gem) rack-mini-profiler-0.1.23/Ruby/lib/mini_profiler/profiling_methods.rb:90:in block in profile_method'
(gem) actionpack-3.2.12/lib/action_controller/metal.rb:203:indispatch'
(gem) actionpack-3.2.12/lib/action_controller/metal/rack_delegation.rb:14:in dispatch'
(gem) actionpack-3.2.12/lib/action_controller/metal.rb:246:inblock in action'
(gem) actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:73:in dispatch'
(gem) actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:36:incall'
(gem) journey-1.0.4/lib/journey/router.rb:68:in block in call'
(gem) journey-1.0.4/lib/journey/router.rb:56:incall'
(gem) actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:601:in call'
(gem) omniauth-1.1.3/lib/omniauth/strategy.rb:177:incall!'
(gem) omniauth-1.1.3/lib/omniauth/strategy.rb:157:in call'
(gem) warden-1.2.1/lib/warden/manager.rb:35:inblock in call'
(gem) warden-1.2.1/lib/warden/manager.rb:34:in call'
(gem) actionpack-3.2.12/lib/action_dispatch/middleware/best_standards_support.rb:17:incall'
(gem) rack-1.4.5/lib/rack/etag.rb:23:in call'
(gem) rack-1.4.5/lib/rack/conditionalget.rb:25:incall'
(gem) actionpack-3.2.12/lib/action_dispatch/middleware/head.rb:14:in call'
(gem) actionpack-3.2.12/lib/action_dispatch/middleware/params_parser.rb:21:incall'
(gem) actionpack-3.2.12/lib/action_dispatch/middleware/flash.rb:242:in call'
(gem) rack-1.4.5/lib/rack/session/abstract/id.rb:210:incontext'
(gem) rack-1.4.5/lib/rack/session/abstract/id.rb:205:in call'
(gem) actionpack-3.2.12/lib/action_dispatch/middleware/cookies.rb:341:incall'
(gem) activerecord-3.2.12/lib/active_record/query_cache.rb:64:in call'
(gem) activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:479:incall'
(gem) actionpack-3.2.12/lib/action_dispatch/middleware/callbacks.rb:28:in block in call'
(gem) activesupport-3.2.12/lib/active_support/callbacks.rb:405:in_run__1802988086567094080__call__1831358325440036178__callbacks'
(gem) activesupport-3.2.12/lib/active_support/callbacks.rb:405:in __run_callback'
(gem) activesupport-3.2.12/lib/active_support/callbacks.rb:385:in_run_call_callbacks'
(gem) activesupport-3.2.12/lib/active_support/callbacks.rb:81:in run_callbacks'
(gem) actionpack-3.2.12/lib/action_dispatch/middleware/callbacks.rb:27:incall'
(gem) actionpack-3.2.12/lib/action_dispatch/middleware/reloader.rb:65:in call'
(gem) actionpack-3.2.12/lib/action_dispatch/middleware/remote_ip.rb:31:incall'
(gem) better_errors-0.7.2/lib/better_errors/middleware.rb:84:in protected_app_call'
(gem) better_errors-0.7.2/lib/better_errors/middleware.rb:79:inbetter_errors_call'
(gem) better_errors-0.7.2/lib/better_errors/middleware.rb:56:in call'
(gem) actionpack-3.2.12/lib/action_dispatch/middleware/debug_exceptions.rb:16:incall'
(gem) actionpack-3.2.12/lib/action_dispatch/middleware/show_exceptions.rb:56:in call'
(gem) railties-3.2.12/lib/rails/rack/logger.rb:32:incall_app'
(gem) railties-3.2.12/lib/rails/rack/logger.rb:16:in block in call'
(gem) activesupport-3.2.12/lib/active_support/tagged_logging.rb:22:intagged'
(gem) railties-3.2.12/lib/rails/rack/logger.rb:16:in call'
(gem) actionpack-3.2.12/lib/action_dispatch/middleware/request_id.rb:22:incall'
(gem) rack-1.4.5/lib/rack/methodoverride.rb:21:in call'
(gem) rack-1.4.5/lib/rack/runtime.rb:17:incall'
(gem) activesupport-3.2.12/lib/active_support/cache/strategy/local_cache.rb:72:in call'
(gem) rack-1.4.5/lib/rack/lock.rb:15:incall'
(gem) actionpack-3.2.12/lib/action_dispatch/middleware/static.rb:62:in call'
(gem) rack-mini-profiler-0.1.23/Ruby/lib/mini_profiler/profiler.rb:310:incall'
(gem) railties-3.2.12/lib/rails/engine.rb:479:in call'
(gem) railties-3.2.12/lib/rails/application.rb:223:incall'
(gem) rack-1.4.5/lib/rack/content_length.rb:14:in call'
(gem) railties-3.2.12/lib/rails/rack/log_tailer.rb:17:incall'
(gem) rack-1.4.5/lib/rack/handler/webrick.rb:59:in service'
/home/neil/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:138:inservice'
/home/neil/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:94:in run'
/home/neil/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/server.rb:191:inblock in start_thread'
I'm trying to order a big array by reputation using the ActiveRecordReputation gem.
Is it possible?
I have a model call Microposts, It has a reputation system called :votes.
Those microposts belongs to other model call Group and a User have many groups.
I need to get all the microposts of the groups that the User is suscribe and order it by reputation.
I get a big array of microposts like this:
@microposts = Micropost.joins(:group => :users).where(:users => {id: current_user.id})
But it stil missing the reputation order.
I hope you can help me!
Hi,
I'm trying to use this gem for assigning "points" for records created inside a CMS. Please let me know if these types of work is possible using this gem.
The CMS is for recording "job" entries for company "Employees" - a Job belongs to a "Category" and Category has a "score" attribute associated. Job entries are created by CMS Managers. All I need is when a Manager create job entry (which belongs to a Category of course), I need to assign relevant score to the "Employee"
Finally I need to Calculate the average score each employee scored comparing to the other employees by Category.
Does this make any sense?
Cheers!
Is there a method to recalculate reputation for a given object?
I've been having issues with STI support (add_or_update_evaluation was previously updating the subclass reputation, while reputation_for is now returning the base class reputation or something else), but anyway, I now have two reputations for every STI object: one for the subclass, one for the base class, and they're both inaccurate, so I need to recalculate reputations somehow. I haven't found anything in the API, both public and private.
Also, STI behavior seems inconsistent: previously it wasn't using the base STI class at all, now it uses the base class for reputations, while still using the subclass name for evaluations.
I have the follows entity:
class App < ActiveRecord::Base
# Rating
has_reputation :rating, source: :user, aggregated_by: :average
end
and
class User < ActivieRecord::Base
end
How can I get the user's rating value for certain app?
Hi,
I ran into a problem when using this gem in the case that the source of a evalution uses STI. I'm also able to reproduce it in a new app.
Let's say we have the following models with the configured reputation system:
class User < ActiveRecord::Base
has_many :posts
end
class Student < User
end
class Professor < User
end
class Post < ActiveRecord::Base
belongs_to :user
has_reputation :votes, source: :user, aggregated_by: :sum
end
When I'm now adding a evalutation with a student object as source post.add_or_update_evaluation(:votes, 1, student)
this Evalutation is stored:
#<ReputationSystem::Evaluation id: 5, reputation_name: "votes", source_id: 2, source_type: "User", target_id: 1, target_type: "Post", value: 1.0, created_at: "2012-11-28 10:42:40", updated_at: "2012-11-28 10:42:40">
As you already see it, uses the base class User
to store Evaluation.
If I want to update the Evaluation now with post.add_or_update_evaluation(:votes, -1, student)
.
I get this:
ReputationSystem::Evaluation Load (0.6ms) SELECT "rs_evaluations".* FROM "rs_evaluations" WHERE "rs_evaluations"."reputation_name" = 'votes' AND "rs_evaluations"."source_id" = 2 AND "rs_evaluations"."source_type" = 'User' AND "rs_evaluations"."target_id" = 1 AND "rs_evaluations"."target_type" = 'Post' LIMIT 1
ReputationSystem::Evaluation Exists (0.6ms) SELECT 1 AS one FROM "rs_evaluations" WHERE "rs_evaluations"."reputation_name" = 'votes' AND "rs_evaluations"."source_id" = 2 AND "rs_evaluations"."source_type" = 'Student' AND "rs_evaluations"."target_id" = 1 AND "rs_evaluations"."target_type" = 'Post' LIMIT 1
(0.1ms) begin transaction
Student Load (1.9ms) SELECT "users".* FROM "users" WHERE "users"."type" IN ('Student') AND "users"."id" = 2 LIMIT 1
ReputationSystem::Evaluation Exists (0.1ms) SELECT 1 AS one FROM "rs_evaluations" WHERE ("rs_evaluations"."source_id" = 2 AND "rs_evaluations"."reputation_name" = 'votes' AND "rs_evaluations"."source_type" = 'User' AND "rs_evaluations"."target_id" = 1 AND "rs_evaluations"."target_type" = 'Post') LIMIT 1
(0.9ms) rollback transaction
ActiveRecord::RecordInvalid: Validation failed: Source has already been taken
from /Users/andre/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/validations.rb:56:in `save!'
from /Users/andre/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/attribute_methods/dirty.rb:33:in `save!'
from /Users/andre/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/transactions.rb:246:in `block in save!'
from /Users/andre/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
from /Users/andre/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
from /Users/andre/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/transactions.rb:208:in `transaction'
from /Users/andre/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
from /Users/andre/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/transactions.rb:246:in `save!'
from /Users/andre/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/validations.rb:41:in `create!'
from /Users/andre/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-reputation-system-2.0.1/lib/reputation_system/models/evaluation.rb:46:in `create_evaluation'
from /Users/andre/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-reputation-system-2.0.1/lib/reputation_system/evaluation_methods.rb:53:in `add_evaluation'
from /Users/andre/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-reputation-system-2.0.1/lib/reputation_system/evaluation_methods.rb:74:in `add_or_update_evaluation'
from (irb):39
Following the backtrace the problem is in add_or_update_evaluation
, the check if a evaluation from this source already exists. Somehow it uses in this case not like in every other case the base class, it uses the class of the object, in this case Student
. So it doesn't find the existing evalution and tries to create a new one which fails.
Do you have any hints to fix this problem?
Thanks, Andrรฉ
First off, this is how my models (the relevant parts) are defined:
class User < ActiveRecord::Base
has_many :comments, dependent: :destroy
has_reputation :comments,
source: { reputation: :comments, of: :comments }
end
class Comment < ActiveRecord::Base
belongs_to :user
has_reputation :comments,
source: :user,
source_of: { reputation: :comments, of: :user }
end
I don't have any problem with adding any other reputations. However, when adding this particular one, I see the following error in both my rails console and when starting the rails server:
/Users/hasghari/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:503:in `load_missing_constant': Expected /Users/hasghari/github/ue/app/models/comment.rb to define Comment (LoadError)
from /Users/hasghari/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:192:in `block in const_missing'
from /Users/hasghari/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:190:in `each'
from /Users/hasghari/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:190:in `const_missing'
from /Users/hasghari/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:230:in `block in constantize'
from /Users/hasghari/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in `each'
from /Users/hasghari/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in `constantize'
from /Users/hasghari/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
from /Users/hasghari/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-2.0.1/lib/reputation_system/network.rb:38:in `get_reputation_def'
from /Users/hasghari/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-2.0.1/lib/reputation_system/network.rb:21:in `has_reputation_for?'
from /Users/hasghari/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-2.0.1/lib/reputation_system/network.rb:59:in `block in add_reputation_def'
from /Users/hasghari/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-2.0.1/lib/reputation_system/network.rb:57:in `each'
from /Users/hasghari/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-2.0.1/lib/reputation_system/network.rb:57:in `add_reputation_def'
from /Users/hasghari/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-reputation-system-2.0.1/lib/reputation_system/base.rb:70:in `has_reputation'
from /Users/hasghari/github/ue/app/models/user.rb:64:in `<class:User>'
from /Users/hasghari/github/ue/app/models/user.rb:1:in `<top (required)>'
Any ideas or suggestions would be greatly appreciated.
Everything was running great in rails 3.0.8. I am upgrading to rails 3.2 eventually but to get things ready Ryan Bates in a Railscast recommended that I upgrade to rails 3.0.17 first. After upgrading to 3.0.17 I got "undefined method `reputation_value_for' for #<User: foo>".
I am running rails in a rvm installed Ruby version 1.9.2. To be sure that it wasn't a problem with gems, I uninstalled 1.9.2 and reinstalled it. I installed the bundler gem and then ran bundle install. It still got the same error.
I then renamed the database migrations and ran rails g reputation_system. The old and new migration files were exactly the same.
Hi, I'm trying to build a reputation system with positive and negative votes, but I would like to know, what was the last evaluation of a user?
If the user gives a positive or negative vote to know wich kind of icon I must show.
How can I do that?
So, my setup is very simple. I got the User model with the following:
has_reputation :score, source: :parking_ticket ,aggregated_by: :sum
First I execute
user.add_evaluation(:score, 15, partking_ticket)
and when I execute
user.evaluators_for(:score)
it returns me all the parking_ticket, OK. But how can I return how much each parking ticket evaluated (the 15 on the example)?
Is there a support for unvoting? I wanted to be able to retract votes. Thanks.
Is there a way to unvote a reputation?
I get the following error undefined method
first_page?' for #Array:0x007fb2fa6dc3b0using the
paginate` method of Kaminari in the view.
Note: I am following http://railscasts.com/episodes/364-active-record-reputation-system for this example.
I have a Location model where I am letting the user rank (i.e. 1 to 5 stars) the item:
has_reputation :location_rating, source: :user, aggregated_by: :average
In my controller I am either deleting the rating:
@location.delete_evaluation(:location_rating, current_user)
or updating it:
@location.add_or_update_evaluation(:location_rating, params[:rating] , current_user)
I am brutally confused how to query:
I am trying @location.reputation_for(:location_rating)
and getting some weird behavior. If a given user deletes a rating and then the new reputation_for
value seems to averaging in the old ratings.
For example:
1.9.3p0 :038 > RSEvaluation.all RSEvaluation Load (1.7ms) SELECT "rs_evaluations".* FROM "rs_evaluations" +----+-----------------+-----------+-------------+-----------+-------------+-------+-------------------------+-------------------------+ | id | reputation_name | source_id | source_type | target_id | target_type | value | created_at | updated_at | +----+-----------------+-----------+-------------+-----------+-------------+-------+-------------------------+-------------------------+ | 46 | tracking | 1 | User | 6 | Location | 0.0 | 2012-08-28 05:15:13 UTC | 2012-08-28 05:15:13 UTC | | 48 | tracking | 1 | User | 5 | Location | 0.0 | 2012-09-04 14:44:37 UTC | 2012-09-04 14:44:37 UTC | | 51 | tracking | 1 | User | 8 | Location | 0.0 | 2012-09-12 06:51:58 UTC | 2012-09-12 06:51:58 UTC | | 52 | tracking | 1 | User | 1 | Location | 0.0 | 2012-09-12 14:54:39 UTC | 2012-09-12 14:54:39 UTC | | 54 | location_rating | 1 | User | 5 | Location | 3.0 | 2012-09-19 05:10:46 UTC | 2012-09-19 05:18:16 UTC | | 56 | tracking | 11 | User | 5 | Location | 0.0 | 2012-09-19 05:47:10 UTC | 2012-09-19 05:47:10 UTC | | 58 | location_rating | 11 | User | 3 | Location | 2.0 | 2012-09-19 06:33:12 UTC | 2012-09-19 06:33:12 UTC | | 61 | location_rating | 11 | User | 5 | Location | 5.0 | 2012-09-19 07:15:42 UTC | 2012-09-19 07:15:42 UTC | +----+-----------------+-----------+-------------+-----------+-------------+-------+-------------------------+-------------------------+
On Location id = 5 should my reputation not be (3 + 5) / 2 = 4? I currently get 2.59375. I update User 11's rating to 1 and the new reputation is 0.59375.
I am sure I am missing something obvious here (newbie).
Dan
Hi,
Does this method work with Rails 4 yet?
This is my gem file:
gem 'activerecord-reputation-system', github: 'NARKOZ/activerecord-reputation-system', branch: 'rails4'
When I try this in my controller nothing gets ordered:
find_with_reputation(:votes, :all, :order => "votes desc")
Thanks
Hello,
my issue is that after starting my local server in production mode the reputation system stops working correctly, current_user.reputation_for(:votes).to_i
returns 0. When running in development mode everything works fine. In my case I have two sources of repution on the user model, it looks like this
user.rb
has_many :posts
has_many :comments
has_reputation :votes, :source => [{ :reputation => :comment_votes, :of => :comments },{ :reputation => :post_votes, :of => :posts}]
post.rb
has_many :comments
belongs_to :user
has_reputation :post_votes, source: :user
comment.rb
belongs_to :post
belongs_to :user
has_reputation :comment_votes, source: :user
Do you have any idea why this may be?
ERROR: Could not find a valid gem 'reputation_system' (>= 0) in any repository
Are you using a non-standard repo?
Given the example model:
class Question < ActiveRecord::Base
belongs_to :author, class_name: 'User'
end
How would be the correct way to define a reputation where the author/User is the source?
has_reputation :votes,
source: :author,
aggregated_by: :sum
Gives a ActiveRecord::RecordInvalid: Validation failed: Source type User is not source of votes reputation
for a.add_evaluation :votes, 1, current_user
for example.
and
has_reputation :votes,
source: :user,
aggregated_by: :sum
Gives a NameError: undefined local variable or method 'user' on an instance of Question.
for a.add_evaluation :votes, 1, current_user
Suppose I have User and Article classes associated like this:
class User < ActiveRecord::Base
has_many :articles
end
class Article < ActiveRecord::Base
belongs_to :user
end
and want to track the following reputations:
Is there a way to implement the 2nd and 3rd types of reputation with this gem?
This is also a SO post: http://stackoverflow.com/questions/18246904/twitter-activerecord-reputation-counting-primary-reputations-as-non-primary-rep
I have two models: Voters and Polls.
A Voter can vote on a Poll in two ways: 1) up/down vote 2) power vote
I have up/down voting working, but I want to be able to know how many power votes a user has accumulated in aggregate as they can only have a certain amount.
poll.rb
class Poll < ActiveRecord::Base
belongs_to :voter
has_reputation :votes,
source: :voter
has_reputation :powervotes,
source: :voter,
source_of: [{reputation: :voter_powervotes, of: :voter}]
has_reputation :score,
source: [
{ reputation: :votes },
{ reputation: :powervotes, weight: 2 }]
def upvote(voter)
self.add_or_update_evaluation(:votes, 1, voter)
end
def downvote(voter)
self.add_or_update_evaluation(:votes, -1, voter)
end
def powervote(voter)
self.add_or_update_evaluation(:powervotes, 1, voter)
end
def score
self.reputation_for(:score).to_i
end
end
voter.rb
class Voter < ActiveRecord::Base
has_many :polls
has_reputation :voter_powervotes,
source: [reputation: :powervotes, of: :polls]
def powervotes
self.reputation_for(:powervotes).to_i
end
end
When I powervote() on a poll as a voter and then call Voter.powervotes it returns 0. I think this is because of STI.
Assuming Voter ID 1 and Poll ID 1, when I record a powervote as a user on a poll, using this setup, 3 reputations are created in my rs_reputations table.
powervotes
voter_powervotes
score
Everything seems fine, until you dig a little deeper: voter_powervotes' target_id seems to be pulling the wrong ID. In this case it's pulling 4 - it should be 1. I think it's doing this because Poll ID 1 has a column called voter_id and its value is 4. I don't care about who the Poll belongs to I just care about each user's powervote count.
Is there a better way to setup the associations between models or have I found a bug?
I've based some code closely off the readme's example:
has_reputation :karma,
:source => [
{ :reputation => :comment_popularity },
{ :reputation => :impression_total }],
:aggregated_by => :sum
has_reputation :impression_total,
:source => { :reputation => :points, :of => :impressions },
:aggregated_by => :sum
has_reputation :comment_popularity,
:source => { :reputation => :votes, :of => :comments },
:aggregated_by => :sum
In my view, I get the results I expect if I display the :impression_total or :comment_popularity like so:
<%= user.reputation_value_for(:impression_total).to_i %>
However, if I try to display :karma, I only get "0"--even if the sum of :impression_total and :comment_popularity should be "15" or "21" or some other number. What might I be doing wrong here?
In Browser:
Getting an "undefined method has_reputation" ... This error occurred while loading the following files: /Users/username/appname/config/routes.rb ... config/routes.rb:6:in `block in <top (required)>'
Same error in Terminal
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/dynamic_matchers.rb:50:in method_missing': undefined method
has_reputation' for #Class:0x007fa581c3ebe0 (NoMethodError)
Error is thrown on the following route:
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
Already tried bundle install, loading directly from master, and restarting local server.
SOLUTION: Require 'reputation_system' in Gemfile:
gem 'activerecord-reputation-system', :require => 'reputation_system'
Hi,
I get this error when I try to delete an evaluation, here is my configuration, I have two model User, Article described as below. This error happens when I invoke
@article.delete_evaluation(:votes, @user)
Here is the article model
class Article < ActiveRecord::Base
belongs_to :contributor, class_name: 'User'
has_reputation :votes, source: :user, aggregated_by: :sum, source_of: [{reputation: :writing_skill, of: :contributor }]
end
Here is the User model
class User < ActiveRecord::Base
has_many :articles, dependent: :destroy, foreign_key: :contributor_id
has_reputation :writing_skill, source: {reputation: :votes, of: :articles }, aggregated_by: :sum
end
I think this because of the dependent destroy of RSReputationMessage
on destroy of RSEvaluation
. There is also a dependency on the destroy of RSReputationMessage
to destroy RSEvaluation
, which results in this error.
I have this in my User model
has_many :evaluations, class_name: "RSEvaluation", as: :source
has_many :questions
has_many :answers
has_reputation :karma,
:source => [
{ :reputation => :questioning_skill },
{ :reputation => :answering_skill } ]
has_reputation :questioning_skill,
:source => { :reputation => :votes, :of => :questions }
has_reputation :answering_skill,
:source => { :reputation => :votes, :of => :answers }
But whenever I user.reputation_for(:karma) I always get 0.0.
No problem with user.reputation_for(:questioning_skill) because I get the correct value.
What if I have a list of links and wanted to check if a user vote
for it or not, I dont want to call over 30 SQL calls if i have listed 30 links!
I have a weird issue and I'm not sure what is causing it.
I have an aggregated reputation called "karma" that is the sum of 3 other reputations
has_reputation :karma,
:source => [
{ :reputation => :comment_votes },
{ :reputation => :review_votes },
{ :reputation => :status_votes }],
:aggregated_by => :sum
has_reputation :comment_votes,
:source => { :reputation => :votes, :of => :comments }
has_reputation :review_votes,
:source => { :reputation => :votes, :of => :reviews }
has_reputation :status_votes,
:source => { :reputation => :votes, :of => :statuses }
In my status model
has_reputation :votes, :source => :user, :aggregated_by => :sum, :source_of => [{ :reputation => :status_votes, :of => :user }]
This reputation setup seems to be working on most of my test users but for one user, the value for karma is 0 even if the user has a non-zero value for :status_votes. user.reputation_for(:status_votes) would return 4 but user.reputation_for(:karma) would be 0. What could be causing this problem?
EDIT: I've noticed that in general Karma is not the sum of the 3 reputation systems. Is my setup wrong?
This would greatly improve the flexibility of the available 'process' options!
Thanks for the great gem!
SHORTENED FOR BREVITY:
Basically, this error can occur if the reputation model is defined using invalid syntax...
HOWEVER,
It can also apparently occur when syntax is kosher according to the Github docs.
Simplest Setup, almost, but doesn't run. I want to create a feedback section for my Spree Shop. Feedback entries shall by up- or downvoted by people.
class Feedback < ActiveRecord::Base ("requires spree/user")
belongs_to :user # from Spree Commerce Engine / Devise
has_reputation :votes, source: :user, aggregated_by: :sum
Decorator for Spree::User : ("requires Feedback")
has_many :feedbacks
has_reputation :votes, source: {reputation: :votes, of: :feedbacks}, aggregated_by: :sum # I do not exactly know if this line is necessary in my case, but outcommenting does not change anything
Controller method "vote" :
value = params[:type] == "up" ? 1 : -1
feedback = Feedback.find(params[:id])
feedback.add_or_update_evaluation(:votes, value, current_user)
FAILS with:
Validation failed: Source type ActiveRecord::Base is not source of votes reputation
Rails.root: /home/oliver/rails_workspace/designer_shop
Application Trace | Framework Trace | Full Trace
activerecord (3.2.12) lib/active_record/validations.rb:56:in save!' activerecord (3.2.12) lib/active_record/attribute_methods/dirty.rb:33:in
save!'
activerecord (3.2.12) lib/active_record/transactions.rb:264:in block in save!' activerecord (3.2.12) lib/active_record/transactions.rb:313:in
block in with_transaction_returning_status'
activerecord (3.2.12) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in transaction' activerecord (3.2.12) lib/active_record/transactions.rb:208:in
transaction'
activerecord (3.2.12) lib/active_record/transactions.rb:311:in with_transaction_returning_status' activerecord (3.2.12) lib/active_record/transactions.rb:264:in
save!'
activerecord (3.2.12) lib/active_record/validations.rb:41:in create!' activerecord-reputation-system (2.0.2) lib/reputation_system/models/evaluation.rb:46:in
create_evaluation'
activerecord-reputation-system (2.0.2) lib/reputation_system/evaluation_methods.rb:53:in add_evaluation' activerecord-reputation-system (2.0.2) lib/reputation_system/evaluation_methods.rb:74:in
add_or_update_evaluation'
Thin outputs the following failing SQL Request:
(0.1ms) begin transaction
ReputationSystem::Evaluation Exists (0.3ms) SELECT 1 AS one FROM "rs_evaluations" WHERE ("rs_evaluations"."source_id" = 2 AND "rs_evaluations"."reputation_name" = 'votes' AND "rs_evaluations"."source_type" = 'ActiveRecord::Base' AND "rs_evaluations"."target_id" = 1 AND "rs_evaluations"."target_type" = 'Feedback') LIMIT 1
(0.1ms) rollback transaction
I strongly suspect source_type ActiveRecord::Base to be a problem, but cannot tell exactly, unfortunately. Inspecting the bare associations works flawlessly.
Other theory is, that the module loading order somehow breaks it.
Any ideas and help appreciated
This issue is related to but different from an earlier issue.
I have a Post model with many Comments. Each comment has a reputation. At the moment, when I load a page, the database is queried for each comment's reputation. I tried eager loading the conventional way:
Comment.includes(:rs_reputation).where(:post_id => self.id)
Unfortunately, this throws the error:
Association named 'rs_reputation' was not found; perhaps you misspelled it?
I get the same error when I pluralize it to "rs_reputations." How else could I eager load the comment reputations?
I'm trying to copy the karma reputation system demonstrated on this page https://github.com/twitter/activerecord-reputation-system but it's not totalling the component values. <%= @user.reputation_for(:karma).to_i %> is showing '0' when it should be 11 for my test user.
Code
<%= @user.reputation_for(:votes).to_i %> #showing as '1' for the test user
<%= @user.reputation_for(:best).to_i %> #showing as '10' for the test user
<%= @user.reputation_for(:karma).to_i %> #should be showing as '11' for the test user but is zero
has_reputation :karma,
:source => [
{ :reputation => :total_vote_points },
{ :reputation => :total_best_points },
{ :reputation => :total_studentvote_points },
{ :reputation => :total_lawyervote_points }]
has_reputation :total_vote_points,
:source => { :reputation => :votes, :of => :answers },
:source_of => { :reputation => :karma, :of => :user } #I've tried it with and without the source line
has_reputation :total_best_points,
:source => { :reputation => :best, :of => :answers},
:source_of => { :reputation => :karma, :of => :user }
has_reputation :total_studentvote_points,
:source => { :reputation => :studentvotes, :of => :answers },
:source_of => { :reputation => :karma, :of => :user }
has_reputation :total_lawyervote_points,
:source => { :reputation => :lawyervotes, :of => :answers},
:source_of => { :reputation => :karma, :of => :user }
I created a reputation system a couple months ago and it was working fine. With the latest update, it's broken. I've been working on the site (though not the reputation system specifically), so the break might be because of something I've done, though I can't figure out what. Anyway, here's what going on now:
I have this line of code in my Impressions class:
@impression.add_evaluation(:points, 1, current_user)
Which throws this error:
votes is not defined for NilClass
"votes" is the name of a reputation belonging to the Comments class. There seems to be some sort of cross-over here.
For reference, here's the relevant snippets of code. The method that's throwing the error:
def create
@impression=Impression.new(params[:impression])
@impression.save
@impression.add_evaluation(:points, 1, current_user)
end
The definition for "points" in the Impressions model:
has_reputation :points, source: :user, aggregated_by: :sum,
:source_of => [{ :reputation => :whuffie, :of => :user }]
The definition for "votes" in the Comments model:
has_reputation :votes,
:source => :user,
:aggregated_by => :sum,
:source_of => [{ :reputation => :whuffie, :of => :user }]
UPDATE:
The problem only appears if a user has not yet received any comments. Once the user has received a comment, then the code works as it should.
Hi ,
When I am using RSEvaluation in user module it throwing error .
has_many :evaluations, :class_name: "RSEvaluation", as: :target .
In console also throwing error when i call RSEvaluation.all
Thanks in Advance,
Ptrasad.
Hi, I have a serious problem with my app, I have a Model call Microposts that have a reputation system call "ups".
Micropost.rb
has_reputation :ups, source: :user, aggregated_by: :sum
User.rb
has_reputation :ups, source: {reputation: :ups, of: :microposts}, aggregated_by: :sum
I have follow the railscast for this gem and I have defined the method of the post request like this:
<%= link_to "xxx", vote_micropost_path(micropost, type: "up"), method: "post", class: "trick_anchor" %>
<%= pluralize micropost.reputation_for(:ups).to_i, "vote" %>
<%= link_to "xxx", vote_micropost_path(micropost, type: "down"), method: "post", class: "trick_anchor" %>
In the controller I have refined my method:
def vote
value = params[:type] == "up" ? 1 : -1
@Micropost = Micropost.find(params[:id])
@x = @micropost.reputation_for(:ups).to_i
@value = @x + (value)
logger.debug "Voto despues: #{@value}"
@micropost.add_or_update_evaluation(:ups, @value, current_user)
end
It seems that it must work, but in the console it show a different result.
How can I update the reputation of a Micropost?
Hello. Thanks for the great gem.
For some reason, user.reputation_for(:votes).to_i
works fine in development, but returns only 0
once deployed to production(Heroku). At the same time, link.reputation_for(:votes).to_i
works in both development and production.
I seem to have similar symptoms to issue#13, but in my case, it's just a single sum calculation, and restarting/redeploying has not fixed the problem.
Do you have any idea why this may be?
link.rb
has_reputation :votes, :source => :user, :aggregated_by => :sum
user.rb
has_reputation :votes, :source => { :reputation => :votes, :of => :links }, :aggregated_by => :sum
has_many :evaluations, :class_name => 'ReputationSystem::Evaluation', :as => :source
I'm using Rails 4 beta 1. When I run
rails generate reputation_system
I get this error:
/Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activemodel-4.0.0.beta1/lib/active_model/deprecated_mass_assignment_security.rb:14:in `attr_accessible': `attr_accessible` is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add `protected_attributes` to your Gemfile to use old one. (RuntimeError)
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activerecord-reputation-system-2.0.2/lib/reputation_system/models/evaluation.rb:25:in `<class:Evaluation>'
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activerecord-reputation-system-2.0.2/lib/reputation_system/models/evaluation.rb:18:in `<module:ReputationSystem>'
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activerecord-reputation-system-2.0.2/lib/reputation_system/models/evaluation.rb:17:in `<top (required)>'
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activerecord-reputation-system-2.0.2/lib/reputation_system.rb:25:in `require'
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activerecord-reputation-system-2.0.2/lib/reputation_system.rb:25:in `<top (required)>'
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activerecord-reputation-system-2.0.2/lib/activerecord-reputation-system.rb:1:in `require'
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activerecord-reputation-system-2.0.2/lib/activerecord-reputation-system.rb:1:in `<top (required)>'
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/bundler-1.3.0/lib/bundler/runtime.rb:72:in `require'
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/bundler-1.3.0/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/bundler-1.3.0/lib/bundler/runtime.rb:70:in `each'
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/bundler-1.3.0/lib/bundler/runtime.rb:70:in `block in require'
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/bundler-1.3.0/lib/bundler/runtime.rb:59:in `each'
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/bundler-1.3.0/lib/bundler/runtime.rb:59:in `require'
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/bundler-1.3.0/lib/bundler.rb:132:in `require'
from /Users/frabrunelle/wikibibli/config/application.rb:6:in `<top (required)>'
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/railties-4.0.0.beta1/lib/rails/commands.rb:44:in `require'
from /Users/frabrunelle/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/railties-4.0.0.beta1/lib/rails/commands.rb:44:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Are there any plans to use strong parameters instead of attr_accessible?
Version 1.1.0 isn't tagged in the repo.
Hi, first I just want to thank you for all the hard work you're doing and have done in creating and supporting this gem.
I have a question that's almost exactly the same as this one.
In the aforementioned issue, you explained that this:
@comment = Comment.find_with_reputation(:reputation_name, :all)
would allow you to access the reputation value like this:
@comment.comment_votes
without additional DB queries.
You said that code like this:
Comment.includes(:reputations)
would not give you the same ability to access the reputation value without another query.
Like the author of the previous issue, I want to eagerly load reputation value, but in my case I want to do so inside of a nested eager loading hash.
My unoptimized code looks like this:
@article = Article.find(1)
@comments = @article.comments.find_with_reputation(:votes, :all, :order => 'votes desc', :limit => 20)
I want to write something with eager loading like this:
@article = Article.includes(comments: :comment_votes).find(1)
and then be able to access comments[0].comment_votes.
So my question is: Is there anyway to eagerly load comment_votes in the way that find_with_reputation does inside of a nested eager loading hash (i.e. Article.includes(comments: :comment_votes) )?
And if there is a way, is it also possible to include conditions on the comments?
Sorry if this is a silly question, as I'm pretty new to Rails, and thanks for any help!
When I combine STI and reputation-system gem, I need do some tricks. Here is the code.
class Tile < ActiveRecord::Base;
has_reputation :likes, :source => :user, :aggregated_by => :sum
end
class ObservationTile < Tile; end
class ActionTile < Tile; end
# run code
@action_tile.add_evaluation(:likes, 1, current_user)
# => Error with no likes reputation for ActionTile
After checking the source code, I found the problem is on ReputationSystem::Network, most methods on ReputationSystem::Network relies on class_name. But the STI subclass has different class_name from it's super class.
So one solution is like this
class Tile < ActiveRecord::Base; end
class ObservationTile < Tile;
has_reputation :likes, :source => :user, :aggregated_by => :sum
end
class ActionTile < Tile;
has_reputation :likes, :source => :user, :aggregated_by => :sum
end
That's not what I need, cause I want the value on column target_type of RSEvaluation stick on "Tile".
So I need override the add_evaluation like this
# file tile.rb
alias_method :original_add_evaluation, :add_evaluation
def add_evaluation(*args)
becomes(Tile).original_add_evaluation(*args)
end
And a final result is
class Tile < ActiveRecord::Base;
has_reputation :likes, :source => :user, :aggregated_by => :sum
%w[add_evaluation delete_evaluation delete_evaluation!].each do |name|
alias_method ":original_#{name}", name
define_method name do |*args|
becomes(Tile).send ":original_#{name}", *args
end
end
end
class ObservationTile < Tile; end
class ActionTile < Tile; end
It's not a bug. I just want to know which one is better.
I have a Comments class which is votable. I want to display which users have voted for a given comment, and whether their vote was positive or negative. Unfortunately, I can't figure out how to access that information. Looking at the migration file, it seems like the "source" attribute is the best bet. However, when I call on "source," I seem to get the Users class, rather than specific users. Any advice?
Following first install, and config per the README, I get:
ActionController::RoutingError - undefined method `has_repuation' for #<Class:0x000001048ed758>:
(gem) actionpack-3.2.8/lib/action_controller/metal/exceptions.rb:11:in `initialize'
(gem) actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:57:in `rescue in controller'
...
(gem) railties-3.2.8/lib/rails/rack/log_tailer.rb:17:in `call'
(gem) rack-1.4.5/lib/rack/handler/webrick.rb:59:in `service'
/Users/Eric/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/Eric/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/Eric/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
when calling Controller#index for the following model:
class Link < ActiveRecord::Base
belongs_to :node
has_reputation :avg_rating,
:source => :user,
:aggregated_by => :average
has_reputation :views,
:source => :user,
:aggregated_by => :sum
has_repuation :karma,
:source => [{ :reputation => :avg_rating },
{ :reputation => :views }],
:aggregated_by => :product,
:source_of => [{ :reputation => :karma, :of => :user },
{ :reputation => :karma, :of => :node }]
gem version 2.0.2
(adding ":require => 'reputation_system' " did not change the error)
Any suggestions?
Also, is the reputation system generated at server load? Or is it necessary to rails g reputation_system & db:migrate upon each change of the code?
I'm hitting what seems to be an internal error within Active Record. I'm running rails 3.2.13, with activerecord-reputation-system 2.0.2. I get an undefined method '+' in this section of code at code called at line 117. I'm not sure what's causing this problem and am hoping for a little help as the trace seems to point to something in active record. The code that calls this is below.
[If there's any additional info needed to help solve this, please just let me know.]
112 solution = Solution.find(@temprating.solution_id)
113 p "solution is #{solution}"
114 admin = User.find(6)
115 if solution.has_evaluation?(:kudos, admin)
116 p "temprating is #{@temprating.rating}"
117 solution.increase_evaluation(:kudos, @temprating.rating, admin)
118 else
119 solution.add_evaluation(:kudos, temp, admin)
120 end
From Beter Error's panel, I can see what the instance variables values are all decidedly not nil. I'm not including the admin user, but it's another regular user record.
#<TempRating id: 13, solution_id: 1944, email: "[email protected]", rating: 1, verified: true, created_at: "2013-04-18 22:50:48", updated_at: "2013-04-18 22:51:42", token: "censored">
#<Solution id: 1944, user_id: 1314, contest_id: 84, title: nil, keyword: nil, summary: "Derp", created_at: "2013-04-12 19:28:01", updated_at: "2013-04-12 19:28:01", rating: -1, comment: nil, winning_status: 0, payment_option: 0>
This line from the solution model defines the reputation system.
has_reputation :kudos, :source => :user,
:source_of => {:reputation => :received_kudos, :of => :user}
It causes this stack trace, where the first two lines here are the print statements from the controller.
"solution is #<Solution:0x007f837837bfb0>"
"temprating is 1"
Started GET "/embryos/verify_temprating/atG9fWrkY13kh93-eg00JQ" for 127.0.0.1 at 2013-04-18 22:16:27 -0400
Processing by EmbryosController#verify_temprating as HTML
Parameters: {"id"=>"atG9fWrkY13kh93-eg00JQ"}
TempRating Load (0.8ms) SELECT "temp_ratings".* FROM "temp_ratings" WHERE "temp_ratings"."token" = 'atG9fWrkY13kh93-eg00JQ' LIMIT 1
CACHE (0.0ms) SELECT "temp_ratings".* FROM "temp_ratings" WHERE "temp_ratings"."token" = 'atG9fWrkY13kh93-eg00JQ' LIMIT 1
(0.4ms) BEGIN
(0.4ms) COMMIT
Solution Load (0.6ms) SELECT "solutions".* FROM "solutions" WHERE "solutions"."id" = $1 ORDER BY solutions.created_at DESC LIMIT 1 [["id", 1944]]
User Load (0.9ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 6]]
ReputationSystem::Evaluation Load (1.0ms) SELECT "rs_evaluations".* FROM "rs_evaluations" WHERE "rs_evaluations"."reputation_name" = 'kudos' AND "rs_evaluations"."source_id" = 6 AND "rs_evaluations"."source_type" = 'User' AND "rs_evaluations"."target_id" = 1944 AND "rs_evaluations"."target_type" = 'Solution' LIMIT 1
CACHE (0.0ms) SELECT "rs_evaluations".* FROM "rs_evaluations" WHERE "rs_evaluations"."reputation_name" = 'kudos' AND "rs_evaluations"."source_id" = 6 AND "rs_evaluations"."source_type" = 'User' AND "rs_evaluations"."target_id" = 1944 AND "rs_evaluations"."target_type" = 'Solution' LIMIT 1
Completed 500 Internal Server Error in 1107ms
NoMethodError - undefined method `+' for nil:NilClass:
(gem) activerecord-reputation-system-2.0.2/lib/reputation_system/evaluation_methods.rb:136:in `change_evaluation_value_by'
(gem) activerecord-reputation-system-2.0.2/lib/reputation_system/evaluation_methods.rb:93:in `increase_evaluation'
app/controllers/embryos_controller.rb:117:in `verify_temprating'
...
It could be great to be able to use creation date of an object as a source to do something like the Hacker News home page. Here are the classical formulas : http://www.seomoz.org/blog/reddit-stumbleupon-delicious-and-hacker-news-algorithms-exposed
Hi , I am using this gem , I want calculate positive and negative votes separately. present it is giving sum . Can you any one suggest ?
Thanks in Advance,
Prasad.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.