NameError: uninitialized constant Sail::Setting when installing
jonnylawrence opened this issue · 7 comments
running on rails 5.2.2 / ruby 2.6.1
rake sail:create_config_file causes NameError: uninitialized constant Sail::Setting
rake sail:load_defaults causes NameError: uninitialized constant Sail::Setting
any clues appreciated?
thanks
@jonnylawrence Thank you for the issue report. Indeed the Rails application was not being initialized when running rake tasks. I will fix it for the next release.
@vinistock Hi, I had the same issue in my own application. same config (2.6.1, 5.2.2), and I fixed it the same way you did.
However it's kind of weird, is it related to ruby 2.6 or the newest rails? Did you find why?
I have an app under 5.2.1 and ruby 2.5.1 and I don't have to do Rails.application.initialize!
in my tasks
@chaadow Hey. I didn't actually try to run the rake tasks with older versions of rails.
The problem seems to be that rake tasks registered by the gem didn't initialize the application and thus had no access to the models. I am not entirely sure why.
The fix for older versions would be initializing the application the way it used to be done in older versions. I would need to create a new rails app using an older version to check how the application is initialized.
Alright I just found out about it!
https://edgeguides.rubyonrails.org/command_line.html#custom-rake-tasks
(in the yellow section)
The tasks needs to depend on the :environment
in order for models to be loaded.
@vinistock Basically here:
task :load_defaults do
Rails.application.initialize!
Sail::Setting.load_defaults(true)
end
becomes :
task load_defaults: :environment do
Sail::Setting.load_defaults(true)
end
@chaadow Oh, you're right. That should probably do it. Would you like to submit a PR for it? If not, I will address it for the next release.
Sure will do now!