index.html.erb
<%= turbo_stream_from "posts" %>
<%= turbo_frame_tag "posts" do %>
<%= render partial:'posts/post', collection: @posts, as: :post %>
<% end %>
_post.html.erb
<% if Current.user.id == post.user_id %>
<div class="d-flex justify-content-between">
<%= link_to edit_post_path(post), title:'Edit', class:"text-secondary",data: { turbo: false } do %>
<i class="fa-solid fa-pen-to-square fs-3"></i>
<% end %>
<%= button_to post, method: :delete, class:'btn btn-danger',title:'Delete' do %>
<i class="fa-solid fa-trash-can"></i>
<% end %>
</div>
<% end %>
post.rb
after_create_commit -> {
broadcast_prepend_to("posts")
}
When I prepend the post after_create_commit the post is getting prepended but not able to get the correct Current.user. So, this <% if Current.user.id == post.user_id %>
condition is getting satisfied after refresh only!
Help me to make it work..!