Skip to content

Commit fddfcdb

Browse files
refactors communities sidebar query
1 parent 3b1ecb0 commit fddfcdb

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

lib/reddit/category.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ defmodule Reddit.Category do
2121
Repo.all(Community)
2222
end
2323

24+
def list_communities_names do
25+
query = from c in Community, select: c.name, order_by: [asc: c.name]
26+
Repo.all(query)
27+
end
28+
2429
@doc """
2530
Gets a single community.
2631

lib/reddit_web/controllers/page_controller.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ defmodule RedditWeb.PageController do
1414
### end
1515

1616
def index(conn, _params) do
17-
communities = Category.list_communities()
17+
communities = Category.list_communities_names()
1818
posts = Post.list_popular_posts()
1919
logged_in_user_id = logged_in(conn.assigns.current_user)
2020
render conn, :index, communities: communities, posts: posts, logged_in_user_id: logged_in_user_id

lib/reddit_web/templates/page/index.html.eex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<ul class="list-group list-group-flush">
4343
<%= for community <- @communities do %>
4444
<li class="list-group-item">
45-
<%= link community.name, to: Routes.community_path(@conn, :show, community.name) %>
45+
<%= link community, to: Routes.community_path(@conn, :show, community) %>
4646
</li>
4747
<% end %>
4848
</ul>

0 commit comments

Comments
 (0)