我的仓库:https ://github.com/czepesch/gloss (turboframes-dev 分支)
我有一个词汇表中的条目列表。删除操作有问题。条目已删除,但页面未重新加载\条目未自动删除。(相同的删除操作在同一页面上没有 turboframe)
glossaries/show.html.haml
= turbo_frame_tag 'tab_content' do
- for entry in @glossary.entries
= entry.term
...
= link_to edit ...
= link_to [@glossary, entry], data: { 'turbo_method': 'delete', turbo_confirm: "are you sure?" }
entries_controller.rb
def destroy
@entry.destroy
respond_to do |format|
format.turbo_stream { render turbo_stream: "turbo_stream.remove(@entry)" }
format.html { redirect_to glossary_path(@glossary) }
format.json { head :no_content }
end
end
服务器日志:
12:57:56 web.1 | Started DELETE "/glossaries/57/entries/8" for ::1 at 2022-01-29 12:57:56 +0100
12:57:56 web.1 | Processing by EntriesController#destroy as TURBO_STREAM
12:57:56 web.1 | Parameters: {"glossary_id"=>"57", "id"=>"8"}
12:57:56 web.1 | Glossary Load (0.1ms) SELECT "glossaries".* FROM "glossaries" WHERE "glossaries"."id" = ? LIMIT ? [["id", 57], ["LIMIT", 1]]
12:57:56 web.1 | ↳ app/controllers/entries_controller.rb:57:in `get_glossary'
12:57:56 web.1 | Entry Load (0.2ms) SELECT "entries".* FROM "entries" WHERE "entries"."glossary_id" = ? AND "entries"."id" = ? LIMIT ? [["glossary_id", 57], ["id", 8], ["LIMIT", 1]]
12:57:56 web.1 | ↳ app/controllers/entries_controller.rb:61:in `set_entry'
12:57:56 web.1 | TRANSACTION (0.1ms) begin transaction
12:57:56 web.1 | ↳ app/controllers/entries_controller.rb:46:in `destroy'
12:57:56 web.1 | Entry Destroy (0.7ms) DELETE FROM "entries" WHERE "entries"."id" = ? [["id", 8]]
12:57:56 web.1 | ↳ app/controllers/entries_controller.rb:46:in `destroy'
12:57:56 web.1 | TRANSACTION (18.3ms) commit transaction
12:57:56 web.1 | ↳ app/controllers/entries_controller.rb:46:in `destroy'
12:57:56 web.1 | Completed 200 OK in 28ms (Views: 0.1ms | ActiveRecord: 19.4ms | Allocations: 2884)