Have you tried a Google search for Rails CMSes? What kind of CMS are you having to build? Would something like Administrate work or do you need a more designerly type of tool?
As other say, create a gem.
Note: A Rails engine is just a gem with a type of setup that allows it to integrate with a Rails app. If the code is just plan ol' Ruby, life is even simpler. Follow one of the tutorials listed above, the RubyGems first gem tutorial, or the Rails plugin tutorial. Rails plugins are helpful if you're not using an Engine, but still want to test your code in the context of a Rail app.
Posted in Eager Loading on Rails 5.1
What's the issue you're facing? Is that you're noticing N+1 queries when you loop over events? Or something else?