-
Notifications
You must be signed in to change notification settings - Fork 337
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
Spring in Rails 6 tries to load ActiveRecord even when AR is not part of the application #601
Comments
Something in your app is defining |
The AR require is triggered from that line, leading me to believe that something configures AR to be autoloaded, but I don't know how to determine what that would be. In any event "my app" has no code, as stated in the above description. I generated it using the standard Rails generator and removed AR railtie. |
oh. Yeah, that is true. |
Try this "--skip-active-record" with "rails new" |
|
I thought simply adding sqlite to the bundle was a sufficient workaround, but per https://stackoverflow.com/questions/58352612/rails-tasks-and-generators-are-failing/58383659#58383659 the application must define a full AR configuration. If this configuration is loaded, i.e. connection(s) to the database are established, this is a rather heavy workaround considering the AR database won't ever be used by any application code. |
I tripped over this as well deploying an application to Heroku. I did not need ActiveRecord, and simply leaving sqlite installed is not compatible with Heroku. It looks like a few indirect dependencies on ActiveRecord precipitated the autoloading. Anyways, the resolution turns out to be relatively straightfoward.
--- a/config/application.rb
+++ b/config/application.rb
@@ -1,6 +1,29 @@
require_relative 'boot'
-require 'rails/all'
+# require 'rails/all'
+
+ # Removed because ActiveRecord:
+ # active_record/railtie
+ #
+ # Removed because precipitates AR load:
+ # action_mailbox/engine
+ # active_storage/engine
+ # action_text/engine
+
+%w(
+ action_cable/engine
+ active_job/railtie
+ action_mailer/railtie
+ action_controller/railtie
+ action_view/railtie
+ rails/test_unit/railtie
+ sprockets/railtie
+).each do |railtie|
+ begin
+ require railtie
+ rescue LoadError
+ end
+end
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -29,7 +29,7 @@ Rails.application.configure do
end
# Store uploaded files on the local file system (see config/storage.yml for options).
- config.active_storage.service = :local
+ # config.active_storage.service = :local
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
@@ -40,10 +40,10 @@ Rails.application.configure do
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
- config.active_record.migration_error = :page_load
+ # config.active_record.migration_error = :page_load
# Highlight code that triggered database queries in logs.
- config.active_record.verbose_query_logs = true
+ # config.active_record.verbose_query_logs = true Hopefully this helps! |
Thanks so much @coderifous ! You really helped me out today |
@coderifous active storage is the point in my case. Thank you |
If I create a skeleton Rails API application, and then remove ActiveRecord from the application, spring still tries to load AR which ultimately fails and prevents generators etc. from working.
This is a regression in Rails 6 - in Rails 5.2 everything works as expected.
I created two applications, which are identical except for version of Rails used.
https://github.com/p-mongo/tests/tree/master/spring-ar-sqlite-5
https://github.com/p-mongo/tests/tree/master/spring-ar-sqlite-6
Generate the app:
Edit
Gemfile
, removing reference tosqlite
.Edit
config/application.rb
, commenting out ActiveRecord and ActiveStorage:Run:
Result:
The text was updated successfully, but these errors were encountered: