Circular dependency detected while autoloading
The circular dependency error sounds possibly like a multi-threading issue to me.
You could try adding lib to eager_load_paths like so in development.rb:
#And it solves the issue.
config.eager_load_paths += ["#{config.root}/lib"]