Skip to content

Commit afa17d1

Browse files
committed
feat: Fix logic for retrieving current user's posts and the view
1 parent 33e5e90 commit afa17d1

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

app/models/post.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class Post < ApplicationRecord
1717

1818
scope :for_current_user, ->(current_user) {
1919
order(created_at: :desc)
20-
.includes(:rich_text_content, :user)
21-
.where(user: current_user)
20+
.includes(:rich_text_content, :author)
21+
.where(author: current_user)
2222
}
2323

2424
validates :slug, uniqueness: true

app/views/posts/me.html.erb

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
<h2 class="fs-4">My Posts</h2>
2-
<%= render "posts", posts: @posts %>
2+
3+
<div id="posts">
4+
<%= render @posts %>
5+
</div>

app/views/posts/show.html.erb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<%= content_for(:title, "AuthPost | #{@post.user.username} - #{@post.title}") %>
1+
<%= content_for(:title, "AuthPost | #{@post.author.username} - #{@post.title}") %>
22
<div class="m-auto">
33
<div class="mb-2 d-flex gap-2 flex-wrap">
44
<%= link_to "Back to posts", posts_path, class: "btn btn-secondary" %>
5-
<% if user_signed_in? && current_user == @post.user %>
5+
<% if user_signed_in? && current_user == @post.author %>
66
<%= link_to "Edit", edit_post_path(@post), class: "btn btn-info" %>
77
<% end %>
8-
<% if user_signed_in? && current_user == @post.user %>
8+
<% if user_signed_in? && current_user == @post.author %>
99
<%= link_to "Delete",
1010
@post,
1111
data: {

0 commit comments

Comments
 (0)