3

In development mode, the Grape API files in our Rails app aren't reloading as they should. We've tried the suggested approach in the Grape README, and referred to what seems to be the key SO post on it (Ruby on Rails 3 - Reload lib directory for each request) but it's not working for some reason.

In the config/application.rb:

config.paths.add File.join("app", "api"), glob: File.join("**", "*.rb")
config.autoload_paths += Dir[Rails.root.join("app", "api", "*")]

And in initializers/reload_api.rb:

if Rails.env == "development"
  api_reloader = ActiveSupport::FileUpdateChecker.new(Dir[Rails.root.join('app', 'api', '**', '*.rb')]) do
    puts ">>>> RELOADING!"
    Rails.application.reload_routes!
  end

  ActionDispatch::Callbacks.to_prepare do
    api_reloader.execute_if_updated
  end
end

When I change a file under app/api, I can see the "RELOADING!" message in the log so I know the api_reloader callback is being invoked. But the changes are not taking effect. This makes me suspect the config.autoload_paths, but it all looks correct.

This is using Rails 3.2. Suggestions would be fantastic, since obviously it's super-annoying to not have reloading working on this stuff.

4

1 回答 1

0

如果您只是为了路线而这样做,我找到了一种解决方法。我正在使用 rake 任务来显示 GRAPE 的路线。

rake任务链接:https ://gist.github.com/pragmaticivan/9a9d925e7bbcc8df72f6

于 2014-10-12T04:43:23.650 回答