sort threads desc time

This commit is contained in:
Ben Harris 2018-02-21 21:24:15 -05:00
parent c04189e42e
commit 7978f4c306
4 changed files with 6 additions and 2 deletions

View File

@ -182,7 +182,7 @@ defmodule Forum do
end
def get_posts_by_thread_id(id) do
from(u in Post, where: u.thread_id == ^id)
from(u in Post, where: u.thread_id == ^id and is_nil(u.parent_id))
end
@doc """

View File

@ -1,12 +1,15 @@
defmodule ForumWeb.ThreadController do
use ForumWeb, :controller
import Ecto.Query
alias Forum.Repo
alias Forum.Thread
def index(conn, params) do
{threads, kerosene} =
Thread
|> order_by(desc: :id)
|> Repo.paginate(params)
threads = Repo.preload(threads, :user)

View File

@ -1,5 +1,6 @@
<div class="panel panel-default">
<div class="panel-body">
<div class="pull-right"><img src="https://tilde.team/~<%= @post.user.name %>/avatar.png" alt="<%= @post.user.name %> avatar"></div>
<%= @post.content |> Forum.md %>
</div>
<div class="panel-footer">

View File

@ -13,7 +13,7 @@
<tr>
<td>
<h4><a href="<%= thread_path(@conn, :show, thread) %>"><%= thread.name %></a></h4>
by: <a href="<%= user_path(@conn, :show, thread.user) %>"><em>~<%= thread.user.name %></em></a>
by: <a href="<%= user_path(@conn, :show, thread.user) %>"><em>~<%= thread.user.name %></em></a> // thread created <%= thread.inserted_at |> Forum.pp_time %>
</td>
<td class="text-right">