如何使用 annotate gem 注释 rails 引擎模型?

问题描述

我正在尝试在 rails 6 项目中注释我的引擎。

在我拥有的 gem 文件中的根应用程序

group :development do
  gem 'annotate'
end

这正如预期的那样工作。当我每次运行迁移时,我所有的模型都会完美地注释

现在我的引擎 Gemfile 路径是 components/engine_mame/Gemfile

我有

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

# Specify your gem's dependencies in engine_mame.gemspec.
gemspec

group :development do
  gem 'annotate'
  gem 'pg'
end

但是当我查看引擎中的模型时,我没有任何注释。 我不确定我做错了什么

谢谢

解决方法

方法 1:使用生成的 rake 任务 (rails g annotate:install) 设置模型路径,在那里查找 model_dir 并使用逗号分隔符设置路径,例如

Annotate.set_defaults(
  'model_dir' => 'app/models,engine_mame/app/models',)

方法 2:每次调用时手动设置路径(逗号分隔,无空格)

bundle exec annotate --model-dir app/models,engine_mame/app/models