首页 > 解决方案 > 如何使用注释 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

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

谢谢

标签: ruby-on-railsrails-enginesannotate

解决方案


方法 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

推荐阅读