Skip to content

Reloading not working correctly (Rails engine) #358

Closed
@lucaspiller

Description

@lucaspiller

I have grape set up within a Rails engine for better separation of concerns, however the reloading suggestion in the documentation doesn't work for me. I also have to set ActiveSupport::Dependencies.explicitly_unloadable_constants.

In the engine config I have this:

# auto reload api in development mode
initializer 'reload_api' do
  if Rails.env.development?
    ActiveSupport::Dependencies.explicitly_unloadable_constants << "API::Resources"

    ["app/resources/**/*.rb"].each do |glob|
      files = Dir["#{API::Engine.root}/#{glob}"]
      reloader = ActiveSupport::FileUpdateChecker.new(files) do
        Rails.logger.info ">> Reloading API"
        Rails.application.reload_routes!
      end
      ActionDispatch::Callbacks.to_prepare do
        reloader.execute_if_updated
      end
    end
  end
end

I have no idea why this works, but heh. Might be worth adding this to the readme or wiki :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions