我正在创建一个reddit克隆。在向我的页面添加向上投票和向下投票的过程中,当我试图查看本地站点时,我得到了这个错误。
NameError in LinksController#index
它说错误在"acts_as_votable“上,我不知道它会出什么问题。它还说
#`的undefined local variable or methodacts_as_votable‘
这是我在link.rb中的代码,位于Sublime中的models--> concerns-->下
class Link < ApplicationRecord
acts_as_votable
我来自PHP,我专门研究了Ruby,但是它可能适用于中的任何东西。我不明白,当acts_as_votable方法在模块中时,您可以将它添加到类中。
class Post < ActiveRecord::Base
acts_as_votable
end
我希望是ActsAsVotable::Extenders::Votable::acts_as_votable。什么允许在不调用模块的情况下运行这个程序?
我试图创建一个Reddit克隆,在其中用户和向上投票和下发投票的帖子。我已经为acts_as_votable gem ()安装并运行了必要的迁移:
# app/models/user.rb
class User < ApplicationRecord
has_many :posts
devise :database_authenticatable, :registerable, :trackable, :validatable
...
acts_as_voter
end
# app/models/post.rb
class Post < Activ
我使用rails方法根据博客的投票数(acts_as_votable)对博客进行排序。
方法是
# @allblogs will be some filtered blogs array
@fetch = []
@most_effective_votes = []
for blog in @allblogs
@most_effective_votes << [blog.id,blog.votes_for]
end
@most_effective_votes = @most_effective_v