dmberko11
dmberko11

Reputation: 467

Trying to return most popular blog post using acts_as_votable

So here's my model:

home_blog.rb

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

schema.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

the view:

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

the controller:

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

I get an error that says undefined method `to_model' for activerecord relation

What am I doing wrong?

Upvotes: 1

Views: 42

Answers (0)

Related Questions