Friday, June 12, 2009

Vote_fu Sort Order by Vote_for

@stories = Story.tally( :conditions => {:votes => {:vote => true}}).paginate :page => params[:page], :per_page => 8

After several attempts, i tried putting this condition, and it seems as if the data are sorted according to the number of vote_for it...

It has already included the association table in the plugin perhaps.

Databse Query

I was having some problem with database querying... googled around, and maybe i should remember to come back to this if i were to encounter them again

http://guides.rubyonrails.org/active_record_querying.html
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html
http://ryandaigle.com/articles/2008/7/7/what-s-new-in-edge-rails-easy-join-table-conditions

Tuesday, June 9, 2009

Pagination

Pagination is used tomanage the population data in a single view such as having..


1 | 2 | 3 | next...


The complete how-tos are at http://wiki.rubyonrails.org/howtos/pagination or page 521 Pragmatic Agile Web Development with Rails 3rd Edition



.paginate is similar to .find but it's able to support the argument for :page => params[:page]



It is also possible to chain the pagination. Like using vote_fu's tally,


@users = User.tally().paginate :page => params[:page], :per_page => 8, :order => "name"



In the view, to have the 1,2,3,next etc...


this code needs to be added <%= will_paginate @models %>