Project

General

Profile

[SOLVED] Simple rake task fails - rake aborted! NameError: uninitialized constant Project

Added by Tobias Arndt almost 9 years ago

I have a rake task that worked in previous Redmine versions and try to migrate it to Redmine 3.2. I hope there is someone with some deeper knowledge here. What am I doing wrong ?

code:

namespace :redmine do
  desc 'Lists all project names'
  task :list_all_projects do
    Project.find_each do |project|
      puts project.name
    end
  end
end

RAILS_ENV=production rake 'redmine:list_all_projects' --trace

** Invoke redmine:list_all_projects (first_time)
** Execute redmine:list_all_projects
rake aborted!
NameError: uninitialized constant Project
/opt/redmine-3.2.0/lib/tasks/test.rake:4:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/task.rb:240:in `call'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/usr/local/rvm/gems/ruby-2.2.1/gems/rake-10.5.0/bin/rake:33:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.2.1/bin/rake:23:in `load'
/usr/local/rvm/gems/ruby-2.2.1/bin/rake:23:in `<main>'
/usr/local/rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => redmine:list_all_projects

RAILS_ENV=production bin/about
Environment:
Redmine version 3.2.0.stable
Ruby version 2.2.1-p85 (2015-02-26) [x86_64-linux]
Rails version 4.2.5
Environment production
Database adapter Mysql2
SCM:
Subversion 1.8.8
Filesystem
Redmine plugins:
piwik_plugin 0.0.1
redmine_dmsf 1.5.6

Thank you !


Replies (1)

RE: Simple rake task fails - rake aborted! NameError: uninitialized constant Project - Added by Tobias Arndt almost 9 years ago

I solved it by myself.

At first I regenerated the code under a different namespace:

RAILS_ENV=production rails g task fpm list_all_projects

new code fpm.rake:

namespace :fpm do
  desc "TODO" 
  task list_all_projects: :environment do
    Project.find_each do |project|
      puts project.name
    end
  end
end

    (1-1/1)