-
Notifications
You must be signed in to change notification settings - Fork 123
Gives me source_type 'ActiveRecord::Base' instead of Model class name #36
Comments
I made an own way simpler solution for my problem in particular. Cannot track the error (if?) down the stack, lacking time. If someone is still interested in the reported problem I'd write a test for it on request and once I got some time left. Thx for reading anyway. Bye |
I have exactly the same problem. In my case i am using the refinerycms framework and like you I do have a refinery user setup, after doing all the necessary steps to set the reputation system, I have tried to add_evaluation on the post model with the refinery user. As result, the same error happened... ActiveRecord::RecordInvalid: Validation failed: Source type ActiveRecord::Base is not source of votes reputation I dont think that the ActiveRecord::Base is the issue since i have tried other examples with ActiveRecord::Base and worked perfectly but it is most likely due to the framework like eCommerce, RefineryCMS, anyway if you have find out a solution to this problem, I would appreciate if you shared it. Thanks. |
ok, after spending the morning debugging the gem inside my application I figured out the problem and it turns out to be a bug which happens when you define a class inside a module (in my case the module is called Refinery, for example Refinery::User). The problem is the following function ReputationSystem::Network.get_reputation_def(target_type, reputation_name)[:source] which takes the name partially and returns only "User" instead of "Refinery::User" as source of the reputation, and afterwards when it compares the source_type = "Refinery::User" with the result of the mentioned method "get_reputation_def" the result is wrong "Refinery::User" != "User" and it raises the exception. I fixed it by cutting out the "Refinery.." part by using the demodulize function, but this just fix my problem not sure if that is how you want to proceed... |
+1 As I said I made up an own simple solution without the gem. But I still remember the error and think you have found the correct solution. I had defined a model within the Spree namespace and most probably that causes the same error. That's a good candidate for a pull request imho. Cheers |
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
The text was updated successfully, but these errors were encountered: