I'm using "acts_as_rated" plugin to rate images
I'm using mislav-will_paginate gem to paginate a list of images
(not really relevant, but also using paperclip to attach the photo to
the "image" model
I figured I could do something like this:
@images = Image.paginate(:page => params[:page], :per_page => 10, :order
=> 'rating_avg')
rating_avg is the name of the average rating in acts as rated
I get this error:
Mysql::Error: Unknown column 'rating_avg' in 'order clause': SELECT *
FROM `images` ORDER BY rating_avg LIMIT 0, 10
I'm using the:
:with_stats_table => true
option
What's the right way to do this rather obvious action of sorting the
output of a rated model and paginating with will_paginate?
thanks,
jp
--
Posted via http://www.ruby-forum.com/.
A little help with this? I never did any stand-alone sql and don't know
an inner from an outer join.
If the class that we apply acts_as_rated to ("images" in my case) winds
up with a
has_one :rating_statistic
and the rating_statistics model
belongs_to :image
and "rating_avg" is a member of the statistics table...
What would the join look like to :order by :rating_avg ?
Thanks Fred. No joy.
This works fine but doesn't order anything (obviously):
@images = Image.paginate(:page => params[:page], :per_page => 10)
This
@images = Image.paginate(:page => params[:page], :per_page => 10, :order
=> 'rating_avg')
gives me this error:
Mysql::Error: Unknown column 'rating_avg' in 'order clause': SELECT *
FROM `images` ORDER BY rating_avg LIMIT 0, 10
And your suggestion (slightly modified by me [single quotes added to
rating_statistics] gives this
@images = Image.paginate(:page => params[:page], :per_page => 10, :joins
=> 'rating_statistics', :order => 'rating_avg')
Mysql::Error: Unknown table 'images': SELECT `images`.* FROM `images`
rating_statistics ORDER BY rating_avg LIMIT 0, 10