我试图使用src属性将html加载到turbo框架中,但是当我加载该框架存在的页面时,我没有看到发出网络请求来获取html。
这是我在呈现的页面上编写的标记:
<%= turbo_frame_tag "new_message", src: new_room_message_path(@room), target: "_top" do %>
<div>
placeholder
</div>
<% end %>以及new_room_message_path视图中匹配的turbo框架:
<h1>New Message</h1>
<%= turbo_frame_tag "new_message", target: "_top" do %>
<%= form_with(model: [ @message.room, @message ]) do |form| %>
<div class="field">
<%= form.text_field :content %>
<%= form.submit "send" %>
</div>
<% end %>
<% end %>当我在浏览器中访问new_room_message_path时,路由和html看起来都不错。
application.js内容:
// Entry point for the build script in your package.json
import "@hotwired/turbo-rails"
import "./controllers"
import * as bootstrap from "bootstrap"我是在rails 7.0.2.3上运行这个的。我安装了gem "turbo-rails"。我看到turbo正在application.js import "@hotwired/turbo-rails"中被导入。
任何关于配置或代码更改的提示我应该尝试或完全丢失?如果有更多的情况会有帮助,我很高兴更新这个问题。
发布于 2022-04-13 15:46:35
当从RoR v6.1和webpacker升级到RoR v7.0和importmap时,我遇到了相同的问题(几乎相同的内容在webpacker文件中)。
当我安装importmap-rails gem时,我没有对gem做一个步骤这一点在自述中有说明。:
./bin/rails importmap:install此任务将创建importmap所需的所有文件和文件夹,以便在Rails项目中正常运行,包括config/impormap.rb。在这个文件中,我添加了以下内容:
pin "application", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin_all_from "app/javascript/controllers", under: "controllers"添加了这些之后,我重新启动了服务器,一切都很完美。
https://stackoverflow.com/questions/71630471
复制相似问题