我只是观看来自http://railsforzombiestwo.codeschool.com/levels/5的视频,其中vid显示了如何使用Ajax淡出删除链接的教程(从8:40 - 11:00)。我尝试这样做但它失败了..没有淡出并消失/页面没有刷新。点击删除按钮后,我手动刷新页面使其消失。这是我的代码:
控制器:
{!! mb_strimwidth($allProduct->{'content_' . trans('language.lang')}, 0, 75, "...") !!}
观看次数:views / _comment.html.erb
def destroy
@post = Post.find(params[:post_id])
@comment = @post.comments.find(params[:id])
@comment.destroy
respond_to do |format|
format.html {redirect_to post_path}
format.js
end
end
destroy.js.erb
<% if current_user && current_user.id == @post.user_id %>
<p>
<%= link_to 'Delete', [comment.post, comment],
method: :delete,
remote: true,
class: "button" %>
</p>
<% end %>
</div>
来自codeschool(railsforzombiestwo),它表明只需要3步。我试着它不适合我。差不多2个月的学习轨道没有基本编程^^'。帮帮我??
答案 0 :(得分:2)
将<div class="comment clearfix">
添加到此div元素<div class="comment clearfix" id="comment_<%= comment.id %>">
$("#comment_<%= @comment.id %>").fadeOut();
然后在destroy.js.erb中执行此操作
POST https://graph.facebook.com/v2.8/_page_id_/
{
"recipient": {
"id": "_my_id_"
},
"message": {
"text": "hello, world!"
}
}
希望有所帮助!
答案 1 :(得分:0)
试试这个
<div class="comment clearfix" id="comment-<%= comment.id %>">
<div class="comment_content">
<p class="comment_name">
<strong><%= comment.name %></strong>
</p>
<p class="comment_body"><%= comment.body %></p>
<p class="comment_time"><%= time_ago_in_words(comment.created_at) %> ago</p>
</div>
<% if current_user && current_user.id == @post.user_id %>
<p> <%= link_to 'Delete', [comment.post, comment], method: :delete, remote: true, class: "button" %> </p>
<% end %>
</div>
</div>
</div>
$("#comment-<%= @comment.id %>").fadeOut();