记录ubuntu24服务器升级ruby3.3-rail7升级过程中的错误


首先本地也要测试nginx+puma的模式的运行。
问题一: bootstrap 的modal不出现了。
原因:webpacker升级到importmap, 缺少了相关的js代码。
解决:

#add this in the app/javascript/application.js
import { Modal } from "bootstrap"


问题二:
Puma caught this error: uninitialized constant Rack::File (NameError)

Why:  There is a  gem 'rack-mini-profiler'  in the Gemfile

How: Delete it or update this gem :
Using rack 3.1.6 (was 3.1.4)
Using rack-mini-profiler 3.3.1 (was 2.3.4)


问题三:
本地测试puma  in production mode
puma5 upto puma6 , puma.rb的配置is changed.
https://github.com/puma/puma/blob/master/docs/systemd.md
nginx  confi
https://github.com/puma/puma/blob/master/docs/nginx.md
https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot

问题四:
devise 这个额gem的问题。注册提示错误:
undefined method `user_url' for an instance of Acme::RegistrationsController

问题五:
本地开发的时候chrome总是会将某些网址比如: http://localhost:3000/recent  自动变成 https://localhost:3000/recent.  因为曾经用过这个 https://localhost:3000/recent. 如何让chrome停止将http变成https呢? 就是清除掉历史缓存,记得一定要全部清除,看清楚:all time。
In addition to cached redirects, HTTP Strict Transport Security (aka HSTS) may be at play. HSTS is a security feature that forces the browser to use HTTPS even when accessing an HTTP URL.

The browser will start using HSTS for a domain after receiving a Strict-Transport-Security header from the server. The browser also ships with a list of domains for which HSTS is enabled by default.

In Chrome, there is a way to delete your domain from HSTS after it was added by the server. Though, you can’t exclude domains that are baked in the browser (this includes popular websites and notably everything under the new .dev TLD)

  1. Go to chrome://net-internals/#hsts. Enter example.com under Delete domain security policies and press the Delete button.
  2. Now go to chrome://settings/clearBrowserData, tick the box Cached images and files and press click the button Clear data.

问题六:
升级后,删除了webpacker和yarn等。action_text 富文本编辑器失效了:
运行:
rails action_text:install
Installing JavaScript dependencies
      append  app/javascript/application.js
      append  config/importmap.rb
      create  app/assets/stylesheets/actiontext.css
To use the Trix editor, you must require 'app/assets/stylesheets/actiontext.css' in your base stylesheet.
   identical  app/views/active_storage/blobs/_blob.html.erb
      create  app/views/layouts/action_text/contents/_content.html.erb
Ensure image_processing gem has been enabled so image uploads will work (remember to bundle!)
        gsub  Gemfile
       rails  railties:install:migrations FROM=active_storage,action_text

问题七
本地测试环境,在chrome上 用 http://localhost:3000 每次post form,之后的跳转都 turbo都将跳转的url变成: https://localhost:3000.  导致错误。
2024-07-11 11:48:03 +0800 HTTP parse error, malformed request: #<Puma::HttpParserError: Invalid HTTP format, parsing fails. Are you trying to open an SSL connection to a non-SSL Puma?>
但是在firefox上却没有这个问题。平时用chrome比较多。这个问题还是要解决。
清cache;没有效果。
检查网页代码发现:

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

HTTP Content-Security-Policy (CSP) **upgrade-insecure-requests**指令指示客户端将该站点的所有不安全 URL(通过 HTTP 提供的 URL)视为已被替换为安全 URL(通过 HTTPS 提供的 URL)。该指令适用于需要重写大量不安全的旧版 URL 的网站。upgrade-insecure-requests指令在 block-all-mixed-content 之前被执行,如果其被设置,后者实际上是空操作。可以设置其中一个,但不能同时设置。

删除后测试: ok , 
这个问题花费了好多时间。 waste a lot of time.

问题八:
pagy 从4. 升级到 8. 
自定义url的方法 pagy_url_for 参数变了。
https://github.com/ddnexus/pagy/blob/master/docs/how-to.md#customize-the-item-name

如果params[:page] 不是数字的时候的异常,以前我需要手动处理page参数不合法的问题,现在不需要了。

问题八
devise  登陆成功跳转问题:跳转回到原来的页面,而不是固定页面。
https://github.com/heartcombo/devise/wiki/How-To:-%5BRedirect-back-to-current-page-after-sign-in,-sign-out,-sign-up,-update%5D

问题九
之前用的render js: 
可以用 render turbo_stream 来替换,
  turbo_frame id="topic_#{@topic.id}"
    p class="text-warning"== @return_msg


      respond_to do |format|
        format.html
        format.turbo_stream do 
          render turbo_stream: [turbo_stream.update(@topic, partial: "download/error", locals: {msg: @return_msg})]
        end
      end

参考:https://www.hotrails.dev/turbo-rails/turbo-frames-and-turbo-streams

问题九
redirect_to  跳出本站的url,需要带参数,如下:

redirect_to "https://rubyonrails.org", allow_other_host: true


 问题十:
stimulus.js 里面有个stream render加载的问题,需要在turbo stream render 这个view之后操作。
这个可以通过,将初始化的 turbo frame里面内容清空,render之后,出现这个element,会触发这个element的 elementTargetConnected(element) 这个方法。将需要的的操作写在里面就可以了。
比如:
h5payTargetConnected(element) {
  document.getElementById('wxh5PaymentBtn').click();
}

问题十一
cap staging deploy --trace
cap aborted!
NameError: uninitialized constant Capistrano::Puma (NameError)

更新 capistrano3-puma 到最新的版本。
阅读量: 1290
发布于:
修改于: