2016-07-06 5 views
0

Ich benutze die folgenden gem und jetzt versuche ich Beiträge nach der Anzahl der Ansichten zu sortieren.Impressionist gem - sortieren Beiträge nach Ansichten

Ich habe die Anweisungen und in meinem Beitrag Modell gefolgt, so habe ich:

is_impressionable :counter_cache => true 

Und in meinem Controller, ich habe:

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

Aber ich erhalte eine Fehlermeldung:

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

Antwort

0

Haben Sie Ihrem Modell ein Feld hinzugefügt?

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.

So fügen Sie tun können:

t.integer :my_column_name, :default => 0 

Read about this moment