我有一张桌子,每行都有一个链接
<%= link_to 'Delete', [lesson.group, lesson], remote: true,method: :delete%>
我希望链接破坏相应的数据库条目并从表中删除相应的行而不重新加载页面。动作是
def destroy
@lesson = @group.lessons.find(params[:id])
@lesson.destroy
respond_to do |format|
if @lesson
format.html { redirect_to edit_group_path(@group), notice:'Succesfully deleted lesson' }
format.js {}
else
format.html { redirect_to edit_group_path(@group), notice:'Error!' }
end
end
end
条目被删除,但我只能在重新加载页面时看到更改,并且控制台抛出
DELETE http://localhost:3000/groups/1/lessons/14 500 (Internal Server Error)
从日志中提取:
Started DELETE "/groups/1/lessons/18" for 127.0.0.1 at 2013-10-24 18:39:22 +0400
Processing by LessonsController#destroy as JS
Parameters: {"group_id"=>"1", "id"=>"18"}
[1m[36mGroup Load (1.0ms)[0m [1mSELECT "groups".* FROM "groups" WHERE "groups"."id" = ? LIMIT 1[0m [["id", "1"]]
[1m[35mLesson Load (1.0ms)[0m SELECT "lessons".* FROM "lessons" WHERE "lessons"."group_id" = 1 AND "lessons"."id" = ? LIMIT 1 [["id", "18"]]
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
[1m[35mSQL (4.0ms)[0m DELETE FROM "lessons" WHERE "lessons"."id" = ? [["id", 18]]
[1m[36m (10.0ms)[0m [1mcommit transaction[0m
Completed 500 Internal Server Error in 35ms
ActionView::MissingTemplate (Missing template lessons/destroy, application/destroy with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
* "C:/Sites/timetable/app/views"
)