So, I have actually two issues, but I bet they are connected to each other.
I have to call a rake task on a legacy app (also the task is legacy) but run into "Don't know how to build task 'environment'" and "uninitilized constant" errors. We're working in Rails 5.2 with ruby 2.5.1.
The rake file is in lib/tasks/migrations/models.build_stuff.rb
It looks like this:
include ActionView::Helpers
namespace :migrations do
namespace :build_stuff do
task build_first_things: :environment do
puts 'Starting building first things'
FirstThings.each { |thing| thing.build! }
puts 'Done!'
end
task build_second_things: :environment do
puts 'Starting building second things'
SecondThings.each { |thing| thing.build! }
puts 'Done!'
end
end
end
So, I call the first task with:
rake -f ./lib/tasks/migrations/models/build_first_things.rake migrations:build_stuff:build_first_things
Here I get the following error:
rake aborted!
NameError: uninitialized constant ActionView
I know, in my example there is not even an ActionView helper used, in the real file, there is.
If, just for testing reasons, I delete the line with include ActionView::Helpers
another error is raised:
rake aborted!
Don't know how to build task 'environment' (See the list of available tasks with `rake --tasks`)
I don't want to call a task 'environment', just need to load the app and access the database.
Does anyone know, why either (or) both things happen?
Thank you very very much :)
*** Solution ***
It worked when calling bin/rails
or bundle exec rake
instead of simply rake
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…