我正在发布新的“推文”,使用 jquery 和 ajax,我可以在不刷新页面的情况下显示新发布的推文。但是在我的视图模板中,我有一个if statement
检查它是否是的current_user
,如果是,则显示删除按钮。
但是 Ajax 不读取if statement
并且不显示删除按钮。如果我刷新页面或删除 if 语句,则会显示删除按钮。这违背了目的,因为该按钮也显示在其他用户的个人资料中。
这是我的看法:
<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>
我的 create.js.erb:$('.tweets').prepend('<%= j render(@tweet)%>')