I am posting new "tweets" and with jquery and ajax I am able to show the newly posted tweet without refreshing the page. But in my view template, I have an if statement that checks if it is the current_user and if so, displays the delete button.
But Ajax does not read the if statement and does not display the delete button. The delete button shows up if I refresh the page or if I remove the if statement. That defeats the purpose since the button shows up on other users' profiles also.
Here is my view:
<ul class="tweets>
<li>
<span><%= tweet.content %></span><br>
<% if current_user?(@user)%>
<%= link_to "Delete" tweet, method: :delete, data: { confirm: "You sure?" } %>
<%end%>
</li>
</ul>
My create.js.erb: $('.tweets').prepend('<%= j render(@tweet)%>')