简体   繁体   中英

what order for rails require gems?

For my project, I use Rubocop to check the code style, the Rubocop require gems should be alphabetically sorted within groups. But when I changed the order, the CI failed, the error as below:

bundle exec rake assets:precompile rake aborted! NameError: uninitialized constant Kaminari::Helpers::Paginator

I have to put the kaminari-mongoid and kaminari-actionview after mongoid , then the CI will pass:

gem 'mongoid', '~> 5.1.5'
gem 'kaminari-mongoid', '~> 1.0.1'  # rubocop:disable Bundler/OrderedGems
gem 'kaminari-actionview', '~> 1.0.1' # rubocop:disable Bundler/OrderedGems

Rails how to decide the required order?

You can use empty lines and/or comments to group the gems, and RuboCop won't bug you about it:

gem 'mongoid', '~> 5.1.5'

# Needs to come after mongoid
gem 'kaminari-mongoid', '~> 1.0.1'

# Needs to come after kaminari-mongoid
gem 'kaminari-actionview', '~> 1.0.1'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM