Hi!
I would like to code a kind of ‘forum’.
I’m using will_paginate and I would like my topics to be order by the
newest answer by topic.
For the moment I have:
- in my controller:
@categorie = Categoriemessage.find(params[:id])
@souscategories = Categoriemessage.find(:all, :conditions => ["parent_id
= ?", params[:id]])
@sujets = Message.paginate :per_page => 10, :page => params[:page],
:conditions => ["sujet_id = ? AND
categorie_id = ?", '0',params[:id]]
- in my helper:
def datedernierereponse(sujet_id)
m = Message.find(:first, :conditions => ["sujet_id = ?", sujet_id],
:order => "datecreation desc")
if m.nil?
m = Message.find(sujet_id)
end
m.datecreation
end
Like this, my application works.
@categorie is the current category of the list
@souscategories are the children’s categories of @categorie.
@sujets is the list of topics showed in the view.
datededernierereponse(sujet_id) is a function giving the date of the
newest answer of a topic.
I don’t how to do:
- order @sujets by the newest answer.
- I would like @sujets to include the topics of the @souscategories,
where ‘categorie_id’ = @souscategories.id
My english isn’t so good, don’t hesitate to ask for more explanation or
a reformulation.
Thanks !