I think it would be worth your while working through some tutorials
and guides. Have a look at the guides at
http://guides.rubyonrails.org/ for a start. Agile Development with
Rails is an excellent book. The tutorial at
http://www.railstutorial.org/ is good. Make sure that any tutorial
you try is for rails 2.3.
For your particular problem I would suggest using named_scope.