From fbc8f7712081ab644c0860f875212c0e11d55753 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Sun, 22 Jun 2014 18:20:48 +0200 Subject: [PATCH] =?UTF-8?q?ordre=20pr=C3=A9sentation=20forum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/forum/forum_topics_controller.rb | 2 +- app/models/forum_topic.rb | 3 +++ app/views/forum/forum_topics/_forum_topic.haml | 4 ++-- app/views/forum/forum_topics/show.haml | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/forum/forum_topics_controller.rb b/app/controllers/forum/forum_topics_controller.rb index ae0b4a3..b959f18 100644 --- a/app/controllers/forum/forum_topics_controller.rb +++ b/app/controllers/forum/forum_topics_controller.rb @@ -5,7 +5,7 @@ class Forum::ForumTopicsController < ApplicationController def index - @forum_topics = ForumTopic.order("created_at DESC").all + @forum_topics = ForumTopic.all end def show diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index 4d66024..53d3812 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -16,6 +16,9 @@ class ForumTopic < ActiveRecord::Base belongs_to :category, :class_name => "ForumCategory" + default_scope :include => :forum_messages, :order => "forum_messages.created_at DESC" + + def username if self.forum_user self.forum_user.firstname.to_s+" "+ diff --git a/app/views/forum/forum_topics/_forum_topic.haml b/app/views/forum/forum_topics/_forum_topic.haml index 31ed234..4286bb2 100644 --- a/app/views/forum/forum_topics/_forum_topic.haml +++ b/app/views/forum/forum_topics/_forum_topic.haml @@ -11,10 +11,10 @@ %td{:style => "width:160px;"} -if forum_topic.forum_messages.count > 1 - =forum_topic.forum_messages.last.username + =forum_topic.forum_messages.order("created_at ASC").last.username %br il y a - =distance_of_time_in_words Time.now, forum_topic.forum_messages.last.created_at + =distance_of_time_in_words Time.now, forum_topic.forum_messages.order("created_at ASC").last.created_at -if moderator? %td diff --git a/app/views/forum/forum_topics/show.haml b/app/views/forum/forum_topics/show.haml index e506363..f611150 100644 --- a/app/views/forum/forum_topics/show.haml +++ b/app/views/forum/forum_topics/show.haml @@ -4,7 +4,7 @@ %h1= @topic.title %br %br -=render @topic.forum_messages +=render @topic.forum_messages.order("created_at ASC") =link_to "ajouter un message", new_forum_forum_message_path(:topic_id => @topic.id), :class => "btn btn-primary", :style => "margin:1em 0em;float:right"