Skip to content

Commit

Permalink
Update filters for posts
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelp committed May 27, 2020
1 parent 5106452 commit e069ae6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 49 deletions.
8 changes: 7 additions & 1 deletion app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ def create
private

def timeline_posts
@timeline_posts ||= Post.all.ordered_by_most_recent.includes(:user)
@timeline_posts ||= Post.find_by_sql(['SELECT p.*
FROM posts p
LEFT JOIN friendships f ON f.user_id = p.user_id
AND f.friend_id = ?
AND f.status = \'a\'
WHERE COALESCE(f.friend_id, p.user_id) = ?
ORDER BY p.created_at DESC', current_user.id, current_user.id])
end

def post_params
Expand Down
6 changes: 3 additions & 3 deletions app/views/posts/_post.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<p class="post-content">
<%= post.content %>
</p>
<div class="post-footer d-flex">
<div class="counter-content"><%= pluralize(post.comments_count, 'comment') %></div>
<div class="counter-content"><%= pluralize(post.likes_count, 'like') %></div>
<div class="post-footer">
<div class="counter-content"><%= pluralize(post.comments.count, 'comment') %></div>
<div class="counter-content"><%= pluralize(post.likes.count, 'like') %></div>
</div>
<div class='post-comments-section'>
<% post.comments.each do |comment| %>
Expand Down
5 changes: 2 additions & 3 deletions app/views/users/user_invitations.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
<span class="profile-link">
<%= link_to 'See Profile', user_path(user), class: 'profile-link' %>
</span>
<%= button_to "Accept", update_friendship_path({friendship: user, new_status: 'a'}), {class: 'btn btn-primary', method: :patch} %>
<%= button_to "Reject", reject_invitation_path(user), class: 'btn btn-primary' %>
<%= button_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %>
<%= button_to 'Accept', update_friendship_path({friendship: user, new_status: 'a'}), {class: 'btn btn-primary', method: :patch} %>
<%= button_to 'Reject', user, method: :delete, data: { confirm: 'Are you sure?' } %>
</li>
<% end %>
</ul>
Expand Down
6 changes: 0 additions & 6 deletions db/migrate/20200526220154_add_count_to_comment_table.rb

This file was deleted.

36 changes: 0 additions & 36 deletions db/migrate/20200526223130_add_seq_and_trigger_to_posts.rb

This file was deleted.

0 comments on commit e069ae6

Please sign in to comment.