toptal / granite

Business Actions architecture for Rails apps

Home Page:https://toptal.github.io/granite/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support using granite in engines

paneq opened this issue · comments

Steps to reproduce

  • Generate mountable, isolated engine
  • add granite action in engines/engine_name/config/routes.rb:
EngineName::Engine.routes.draw do
  resources :somethings, only: [] do
    member do
      granite 'engine_name/somethings/action_name#modal'
    end
  end
end

  • get an exception when linking
Seems like EngineName::Somethings::ActionName::ModalProjector was not mounted. Do you have engine_name/somethings/action_name#modal declared in routes?
granite (0.9.2) lib/granite/projector/helpers.rb:55:in `fetch_corresponding_route'
granite (0.9.2) lib/granite/projector/helpers.rb:43:in `corresponding_route'
granite (0.9.2) lib/granite/projector/helpers.rb:37:in `required_params'
granite (0.9.2) lib/granite/projector/helpers.rb:22:in `action_url'
granite (0.9.2) lib/granite/projector/helpers.rb:31:in `action_path'
granite (0.9.2) lib/granite/projector/controller_actions.rb:30:in `confirm_path'

The answer is: yes, I have it declared but the engine is isolated and the granite cache does not seem to handle it:

      def fetch_corresponding_route
        Rails.application.routes.routes.granite_cache[*route_id] || fail(ActionNotMountedError, self)
      end

Resources

The workaround is to use:

Rails.application.routes.draw do

in the engine routing file.