1

所以这是我的模型:

home_blog.rb

def self.highest_voted
     self.order("cached_votes_score DESC")
end

架构.rb

  create_table "home_blogs", force: :cascade do |t|
    t.string "name"
    t.text "entry"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string "image"
    t.integer "cached_votes_score", default: 0
    t.integer "cached_votes_total", default: 0
    t.integer "cached_votes_up", default: 0
    t.integer "cached_votes_down", default: 0
    t.index ["cached_votes_down"], name: "index_home_blogs_on_cached_votes_down"
    t.index ["cached_votes_score"], name: "index_home_blogs_on_cached_votes_score"
    t.index ["cached_votes_total"], name: "index_home_blogs_on_cached_votes_total"
    t.index ["cached_votes_up"], name: "index_home_blogs_on_cached_votes_up"
  end

风景:

<div>
          <%= link_to "Most Popular", @highest_voted %>
        </div>

控制器:

def index
    @home_blogs = HomeBlog.order('created_at DESC').paginate(:page => params[:page], :per_page => 3)
    @highest_voted = HomeBlog.highest_voted.limit(1)
  end

我收到一个错误,提示未定义方法“to_model”用于 activerecord 关系

我究竟做错了什么?

4

0 回答 0