0

I'm using the following gem and now I'm trying to sort posts by the number of views.

I have followed the instructions and in my post model, so I have:

is_impressionable :counter_cache => true

And in my controller, I have:

@mostpopular = @posts.order('counter_cache DESC').limit(6)

But I'm getting an error:

SQLite3::SQLException: no such column: counter_cache: SELECT "posts".* FROM "posts" ORDER BY counter_cache DESC LIMIT 6

cdomination
  • 605
  • 1
  • 7
  • 25
Gurmukh Singh
  • 1,875
  • 3
  • 24
  • 62

1 Answers1

0

Did you added field to your model?

is_impressionable :counter_cache => true

This will automatically increment the impressions_count column in the included model. Note: You'll need to add that column to your model.

To add you can do:

t.integer :my_column_name, :default => 0

Read about this moment

Farkhat Mikhalko
  • 3,565
  • 3
  • 23
  • 37