Search code examples
ruby-on-railsrails-enginesannotate

How to annotate rails engine models with the annotate gem?


I am trying to annotate my engines inside of a rails 6 project.

on the root app in the gem file I have

group :development do
  gem 'annotate'
end

and this works just as expected. When every I run migrations all my models annotate perfectly

now my engine Gemfile path is components/engine_mame/Gemfile

and I have

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

but when I look at the models in my engine I do not have any annotations. I am not sure what I am doing wrong

Thanks


Solution

  • method 1: set paths to models using generated rake task (rails g annotate:install), look for model_dir there and set paths using comma separator, e.g.

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

    method 2: set paths manually on each call (comma-seeparated, without space)

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