Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

ruby on rails - Uninitialized constant 'ActionView' / Don't know how to build task 'environment' in rake task

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/railsor bundle exec rakeinstead of simply rake.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...