我的回购:https://github.com/czepesch/gloss (涡轮框架开发分公司)
我在一个词汇表中有一个条目的列表。删除操作出现问题。条目将被删除,但页面不会重新加载\条目,不会自动删除。(同一页上没有涡轮帧的相同删除操作)
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)发布于 2022-02-03 21:59:50
所以,我的问题主要是与我的误解框架和id的。在我清理了我的代码,把一些部分移到部分,我解决了这个问题,只是给元素正确的标签。主计长保持不变:
entries_controller
respond_to do |format|
format.turbo_stream { render turbo_stream: "turbo_stream.remove(@entry)" }使用turbo_frame_tag显示移到分部的条目:
views/entries/_entry.html.haml
= turbo_frame_tag entry do
- for entry in @glossary.entries
= entry.term
...在视图中,我创建了一个带有id条目的div
%turbo-frame#entries
= render @glossary.entrieshttps://stackoverflow.com/questions/70905302
复制相似问题