Ruby on rails activerecord信誉系统的即时加载
我有一个帖子模型,它使用Twitter的activerecord声誉系统来跟踪投票: 后模型:Ruby on rails activerecord信誉系统的即时加载,ruby-on-rails,eager-loading,Ruby On Rails,Eager Loading,我有一个帖子模型,它使用Twitter的activerecord声誉系统来跟踪投票: 后模型: has_reputation :votes, source: :user, aggregated_by: :sum 我正在尝试加载与索引页上的所有帖子相关联的声誉。下面,我将尝试使用: Post.find_with_reputation(:votes, :all, { :conditions => ["post_id = ?", self.id] }) 执行此操作时,会出现以下错误: und
has_reputation :votes, source: :user, aggregated_by: :sum
我正在尝试加载与索引页上的所有帖子相关联的声誉。下面,我将尝试使用:
Post.find_with_reputation(:votes, :all, { :conditions => ["post_id = ?", self.id] })
执行此操作时,会出现以下错误:
undefined method `id' for #<PostsController:0x007f8560c88150>
我的视图中出现以下错误:
undefined method `votes' for #<Post:0x007f8560a6b610>
有没有关于我哪里出错的方向?你可以用这种方式
@all_videos = Video.includes(:user,:reputations,:tags,:comments).where("videos.user_id !=?",current_or_guest_user.id).paginate(:page =>params[:page], :per_page => 10).find_with_reputation(:views, :all, order: "views desc")
包括使用进行快速加载的帮助?就像你的把手-谢谢你的建议。我尝试了一个稍微修改过的版本:@postsswithrep=Post.includes:user,:reputations.whereposts.user_id!=?,当前\u user.id.find\u的\u信誉:投票,:all,order:vows desc,但不幸的是,这仍然给了我未定义的方法投票。。调用@postwithrep[0]时。votes@dmt2989..try更改为该选项有_many:evaluation,class_name:RSEvaluation,as::source有_声誉:投票,source:{声誉::投票,of::self},汇总单位::sum@Milind-不幸的是,当我试图调用view@dmt2989...i我认为您没有正确配置activerecord\u声誉gem。请检查并告诉我您遵循了相同的配置。
@all_videos = Video.includes(:user,:reputations,:tags,:comments).where("videos.user_id !=?",current_or_guest_user.id).paginate(:page =>params[:page], :per_page => 10).find_with_reputation(:views, :all, order: "views desc")