在 Rails 6 中更改文件后主动模型序列化程序自动重新加载的问题

问题描述

我在子文件app/decorators

中创建了一个文件
# app/models/document.rb

class Document < ApplicationRecord
  def url
    # ...
  end
end

和定义的序列化器:

class DocumentSerializer < ActiveModel::Serializer
  attributes :url
end

当我更改方法 def url 时,Rails 6 重新加载模型但不重新加载序列化程序,因此我需要重新启动服务器。

我尝试将子文件添加autoload_paths,但不幸的是,它没有帮助:

module MyApp
  class Application < Rails::Application
    config.load_defaults 6.0
    # config.autoloader = :classic
    # config.autoload_paths += Dir[Rails.root.join("app","serializers","**","*.{rb}")]
    # ...
  end
end

此外,我已经尝试应用这些答案,但没有任何帮助:

Rails doesn't detect file changes and config.reload_classes_only_on_change makes the server too slow

Custom folders not auto-reloading in Rails 6

active model serializer not working with rails-api gem

附言

Rails 6.1.0

红宝石 2.7.2p137

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...