I have a table with links on each line
<%= link_to 'Delete', [lesson.group, lesson], remote: true, method: :delete%>
The goal is to delete the corresponding database entry and remove the line from the table without refreshing the page. The destroy action is defined as:
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:'Lesson successfully deleted' }
format.js {}
else
format.html { redirect_to edit_group_path(@group), notice:'Error!' }
end
end
end
Even though the entries are being removed, the changes are not visible until the page is reloaded, and the console shows:
DELETE http://localhost:3000/groups/1/lessons/14 500 (Internal Server Error)
Log excerpt:
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"
)