-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reloading not working correctly (Rails engine) #358
Comments
I would love this added to the README, but I do also want an explanation of what |
Sorry I forgot about this. From the Rails docs: "An array of constant names that need to be unloaded on every request. Used to allow arbitrary constants to be marked for unloading." Again, why it works I do not know. It doesn't reload them on every request, only when the resources have changed - but without that line nothing is reloaded. |
Ok, this makes at least some sense. Could you make a pull request with the README update, please? |
finally |
@ccpp0 Can you PR this into the README, please? |
@lucaspiller Bump? |
1 similar comment
@lucaspiller Bump? |
Using |
This seems relevant: #658. Can someone take a look and finish this? |
I made a change based on all of this in #849, if something is not right there, please open a new issue / PR. |
I'm having the same problem in Rails 5. I have this in an initializer: # See https://github.com/ruby-grape/grape#reloading-api-changes-in-development
if Rails.env.development? || Rails.env.test?
ActiveSupport::Dependencies.explicitly_unloadable_constants << 'MyEngine::API'
api_files = Dir[MyEngine::Engine.root.join('lib', '**', '*.rb')]
api_reloader = ActiveSupport::FileUpdateChecker.new(api_files) do
Rails.application.reload_routes!
end
ActiveSupport::Reloader.to_prepare do
api_reloader.execute_if_updated
end
end And in my engines routes.rb file I have, fairly vanilla:
When I first load the app the grape api works fine and the API result is returned. If i change smoething in api.rb it appears to auto-reload fine. However, when I visit the main application's routes, then it errors with:
The weird thing is that file does exit, and does correctly autoload the first time. After visiting the main app's route, the nested Grape API no longer works either. This still errors even if I explicitly require above: MyEngine::Engine.routes.draw do
require_dependency MyEngine::Engine.root.join('lib', 'my_engine', 'api.rb').to_s
mount MyEngine::API => 'coverage'
end The require_dedpendency works fine, but the next line errors after a reload |
ActiveSupport::Dependencies private API has been deleted in Rails 7. What should we do now? |
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:
I have no idea why this works, but heh. Might be worth adding this to the readme or wiki :)
The text was updated successfully, but these errors were encountered: