I finnally found the problem. It is caused by a Rails middleware gem I used to check UserAgent called browser.
I have the following code to only allow "modern browsers" to access my site
Rails.configuration.middleware.use Browser::Middleware do
next if (browser.bot? or browser.search_engine?)
redirect_to upgrade_path unless browser.modern?
end
As rails console has no UserAgent setting, it always redirects to /upgrade.
I update the code to:
Rails.configuration.middleware.use Browser::Middleware do
next if (browser.bot? or browser.search_engine? or (Rails.env == 'test') or (Rails.env == 'development') )
redirect_to upgrade_path unless browser.modern?
end
Now it works!