我想使用 Ajax 进行简单的删除,但这不起作用,我想要让 JQuery 淡出,但这不起作用,我删除并且 tr 不会消失。
我的 application.js 是
$('.delete_post').bind('ajax:success', function() {
$(this).closest("tr").fadeOut();
});
我的人员控制器是
def destroy
@person = Person.find(params[:id])
@person.destroy
respond_to do |format|
format.html { redirect_to people_url }
format.js { render :nothing => true }
end
end
我的观点 index.html.erb
<tr>
<td><%= person.name %></td>
<td><%= person.birth %></td>
<td><%= person.email %></td>
<td><%= link_to 'Show', person %></td>
<td><%= link_to 'Edit', edit_person_path(person) %></td>
<td><%= link_to 'Destroy', person ,method: :delete, data: { confirm: 'Are you sure?' },:remote=> true, :class =>'delete_post' %></td>
</tr>
我正在学习 Ajax,但这不起作用,删除发生但 ajax 不起作用我在视图中包含此标签
<%= javascript_include_tag :defaults %>
但什么都不改变
日志是:
Started DELETE "/people/20" for 127.0.0.1 at 2012-09-03 15:23:45 -0300
Processing by PeopleController#destroy as JS
Parameters: {"id"=>"20"}
[1m[35mPerson Load (0.0ms)[0m SELECT `people`.* FROM `people` WHERE `people`.`id` = ? LIMIT 1 [["id", "20"]]
[1m[36mSQL (0.0ms)[0m [1mBEGIN[0m
[1m[35mSQL (0.0ms)[0m DELETE FROM `people` WHERE `people`.`id` = ? [["id", 20]]
[1m[36m (46.9ms)[0m [1mCOMMIT[0m
Rendered text template (0.0ms)
Completed 200 OK in 94ms (Views: 46.9ms | ActiveRecord: 46.9ms)