Proof of Concept: A Hanami slice in a Rails app

:wave:

With a lot of help from this community (thank you @timriley, @cllns, @alassek!) I managed to get a proof of concept working that shows a slice running inside of a Rails app:

The most interesting piece to check out is probably the config/initializer/load_hanami.rb, which does all needed Hanami configuration. This currently only works with branches of hanami and hanami-view that Tim made a couple weeks ago - these branches fix autoloading when not all (most?) hanami gems are present in the Gemfile.

Anyways, leaving this here for posterity: Maybe this is interesting to someone and they can build on it!

3 Likes

To follow up on the solution to making sure Hanami doesn’t try to load files from app, A hanami slice in a Rails app - #4 by cllns

I suggested

  class App < Hanami::App
    prepare_container do |container|
      container.autoloader.ignore("app")
    end
  end

I think a better approach would be:

  class App < Hanami::App
    config.no_auto_register_paths << "app"
  end

This should accomplish the same thing, by keeping Hanami’s registration code out of that folder altogether, instead of just instructing zeitwerk to ignore that folder.

With the original approach I gave, there are keys for Rails components in Hanami.app.container (which it can’t load).

1 Like