-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RailsAdmin & letsrate Error (Rails4) #38
Comments
These links helped me to solve the problem (actually I've got the error on dashboard load) Instead of writing letsrate_rateable :content in my model, I've copied "letsrate_rateable" method code and specified the source_type for has_many *_raters association. has_many :rates_without_dimension, :as => :rateable, :class_name => "Rate", :dependent => :destroy, :conditions => {:dimension => nil}
has_many :raters_without_dimension, :through => :rates_without_dimension, :source => :rater
has_one :rate_average_without_dimension, :as => :cacheable, :class_name => "RatingCache",
:dependent => :destroy, :conditions => {:dimension => nil}
has_many :content_rates, :dependent => :destroy,
:conditions => {:dimension => :content.to_s},
:class_name => "Rate",
:as => :rateable
has_many :content_raters, :through => :content_rates, :source => :rater, **:source_type => "User"**
has_one :content_average, :as => :cacheable, :class_name => "RatingCache",
:dependent => :destroy, :conditions => {:dimension => :content.to_s} And it works. |
Tx a lot Your solution works fine. There was indeed that problem. has_many "#{dimension}_raters".to_sym, :through => "#{dimension}_rates", :source => :rater it should be has_many "#{dimension}_raters".to_sym, :through => "#{dimension}_rates".to_sym, :source => :rater As I had many models, I put my code in a concern under app/models/concerns. require 'active_support/concern'
module Concerns::Myletsrate extend ActiveSupport::Concern
module ClassMethods
def my_letsrate_rateable(*dimensions)
has_many :rates_without_dimension, -> { where dimension: nil}, :as => :rateable, :class_name => "Rate", :dependent => :destroy
has_many :raters_without_dimension, :through => :rates_without_dimension, :source => :rater
has_one :rate_average_without_dimension, -> { where dimension: nil}, :as => :cacheable,
:class_name => "RatingCache", :dependent => :destroy
dimensions.each do |dimension|
has_many "#{dimension}_rates".to_sym, -> {where dimension: dimension.to_s},
:dependent => :destroy,
:class_name => "Rate",
:as => :rateable
has_many "#{dimension}_raters".to_sym, :through => "#{dimension}_rates".to_sym, :source => :rater, source_type: "User"
has_one "#{dimension}_average".to_sym, -> { where dimension: dimension.to_s },
:as => :cacheable, :class_name => "RatingCache",
:dependent => :destroy
end
end
end
end Then add this to config/initializers/rails_admin.rb: config.excluded_models = Dir.glob(Rails.root.join('app/models/concerns/**.rb')).map {|p| 'Concerns::' + File.basename(p, '.rb').camelize } Finally in each model rateable I add this include Concerns::Myletsrate
my_letsrate_rateable "feelings" It works. |
After installation of letsrate
when I'm trying to edit any of my model in RailsAdmin I get
ActiveRecord::Reflection::ThroughReflection#foreign_key delegated to source_reflection.foreign_key, but source_reflection is nil
but in general letsrate works!
The text was updated successfully, but these errors were encountered: