You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

生产环境Turbo Rails功能失效问题排查求助

Rails生产环境Turbo Frames失效问题排查

我已将首个Rails应用以生产模式部署至Digital Ocean Droplet,本地开发环境中Turbo Frames可正常工作,但生产环境下Turbo Rails完全失效。当前使用ruby 3.1.3、rails 7.0.6,原本应通过Turbo Frame工作的链接表现为普通HTML链接,浏览器控制台无错误提示,production.log也无错误,仅显示点击Turbo Frame链接时请求表现为普通HTML链接行为。

已尝试操作

  • 执行命令:RAILS_ENV=production rails turbo:install
  • 执行命令:RAILS_ENV=production rails turbo:install:redis
  • 重启nginx服务器

补充说明

失效表现为:turbo_frame_tags内的链接点击后未更新指定Turbo Frame内容,而是刷新整页。作为Rails新手已排查所有可检查项,执行assets:precompile未报错。

相关代码片段

edit.html.erb:

<div class="top-padding">
  <%= turbo_frame_tag "new_item" %>
  <%= link_to "Agregar ítem", new_invoice_invoice_item_path(@invoice), data: { turbo_frame: "new_item" }, class: "btn btn-info" %>
</div>

new.html.erb:

<%= turbo_frame_tag "new_item" do %>
  <%= render 'form' %>
<% end %>

本地开发环境中,点击edit页面的link_to会将new页面内容渲染到edit页面的"new_item" Turbo Frame内。开发环境日志显示使用turbo_rails/frame.html.erb布局,生产环境日志显示使用application.html.erb布局。

更新进展

已完成以下检查:

  • 已执行RAILS_ENV=production rails turbo:install
  • app/javascript/application.js包含import "@hotwired/turbo-rails"
  • layouts/application.html.erb包含<%= javascript_importmap_tags %>
  • config/importmap.rb包含pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
  • 无app/assets/javascripts文件夹
  • 浏览器网络面板显示turbo.min-xxx.js已加载
  • 本地与生产代码无差异

内容的提问来源于stack exchange,提问作者Fernando Schlosser

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 18:05:27