rake aborted! uninitialized constant <ClassName> - ruby-on-rails

Hi um quite new to rails and currently working on a task definition in rake file . This is my code
test_task.rake
namespace :test_name_space do
namespace :to do
task :my_task do
p "========================="
sample_out_put = SOutput.new
sample_out_put.createfileoutput
end
end
end
and in my SOutput
class SOutput
def createfileoutput
current_time = Time.new
puts "====================================="
puts "This is a scheduled file output"
puts "====================================="
File.open("/home/kalanamith/Desktop/out.txt", "a+") do |file|
p current_time.inspect.to_s
file.write("This is a sample test")
file.write(current_time.inspect.to_s)
end
end
fileoutput = SOutput.new
fileoutput.createfileoutput
end
and when I run the
rake test_name_space:to:my_task
"========================="
rake aborted!
uninitialized constant SOutput
um getting above error
I dont have a big picture about this error. Can anyone guide me?
/home/kalanamith/Documents/rails_rnd/rails_cron/lib/tasks/test_task.rake:6:in `block (3 levels) in <top (required)>'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/var/lib/gems/1.9.1/gems/rake-10.0.4/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:19:in `load'
/usr/local/bin/rake:19:in `<main>'
Tasks: TOP => test_name_space:to:my_task

try adding:
....
task :my_task => :environment do
....

Related

ActiveRecord::StatementInvalid: Could not find table when run 'rake db:migrate:reset'

Rails version 4.2.5
Ruby version 2.3.1p112
When I run 'rake db:migrate:reset', I get an ActiveRecord::StatementInvalid error.
The error message says "Could not find table 'pass_codes'".
This error is in the !exists?(code: code) line.
Shouldn't it be a class method?
Please let me know if anyone can help me.
Thanks.
class PassCode < ActiveRecord::Base
# Some parts are omitted.
validates :code, presence: true, uniqueness: true
validates_format_of :code, with: /\A\d{8}\z/
def self.generate_unique_code
100.times do
generated_code = sprintf(
"%012d" % SecureRandom.random_number(1_0000_0000)
)
if code_unique?(generated_code)
return generated_code
end
end
end
def self.code_unique
def self.code_unique?(code)
!exists?(code: code)
end
end
FactoryGirl.define do
factory :pass_code do
code PassCode.generate_unique_code
end
end
full stack trace
$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
ActiveRecord::StatementInvalid: Could not find table 'pass_codes'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/sqlite3_adapter.rb:511:in `table_structure'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/sqlite3_adapter.rb:385:in `columns'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/schema_cache.rb:43:in `columns'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/attributes.rb:93:in `columns'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/attributes.rb:98:in `columns_hash'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/relation/query_methods.rb:969:in `block in create_binds'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/relation/query_methods.rb:967:in `each'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/relation/query_methods.rb:967:in `partition'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/relation/query_methods.rb:967:in `create_binds'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/relation/query_methods.rb:954:in `build_where'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/relation/query_methods.rb:584:in `where!'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/relation/query_methods.rb:574:in `where'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/relation/finder_methods.rb:295:in `exists?'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/querying.rb:3:in `exists?'
/Applications/MAMP/htdocs/atmoph/chamonix/app/models/pass_code.rb:61:in `code_unique?'
/Applications/MAMP/htdocs/atmoph/chamonix/app/models/pass_code.rb:54:in `block in generate_unique_code'
/Applications/MAMP/htdocs/atmoph/chamonix/app/models/pass_code.rb:50:in `times'
/Applications/MAMP/htdocs/atmoph/chamonix/app/models/pass_code.rb:50:in `generate_unique_code'
/Applications/MAMP/htdocs/atmoph/chamonix/spec/factories/pass_codes.rb:16:in `block (2 levels) in <top (required)>'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:18:in `instance_eval'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:18:in `factory'
/Applications/MAMP/htdocs/atmoph/chamonix/spec/factories/pass_codes.rb:15:in `block in <top (required)>'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:49:in `instance_eval'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:49:in `run'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:7:in `define'
/Applications/MAMP/htdocs/atmoph/chamonix/spec/factories/pass_codes.rb:14:in `<top (required)>'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `block in load'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/factory_girl-4.5.0/lib/factory_girl/find_definitions.rb:20:in `block (2 levels) in find_definitions'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/factory_girl-4.5.0/lib/factory_girl/find_definitions.rb:19:in `each'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/factory_girl-4.5.0/lib/factory_girl/find_definitions.rb:19:in `block in find_definitions'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/factory_girl-4.5.0/lib/factory_girl/find_definitions.rb:15:in `each'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/factory_girl-4.5.0/lib/factory_girl/find_definitions.rb:15:in `find_definitions'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/factory_girl_rails-4.6.0/lib/factory_girl_rails/railtie.rb:21:in `block in <class:Railtie>'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:44:in `each'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/application/finisher.rb:62:in `block in <module:Finisher>'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `run'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:54:in `run_initializers'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/application.rb:352:in `initialize!'
/Applications/MAMP/htdocs/atmoph/chamonix/config/environment.rb:11:in `<top (required)>'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/application.rb:328:in `require_environment!'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/application.rb:457:in `block in run_tasks_blocks'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `each'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `invoke_prerequisites'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/oyuka/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
./bin/rake:4:in `<main>'
Tasks: TOP => db:migrate => environment
'''
You shouldn't be invoking any FactoryGirl code when running rake db:migrate. Other people have had similar issues years ago, but since you on an older version of rails and factory_girl you are likely running into these older issues. If you google "rails db:migrate factory_girl" you'll find several examples. Here is one with some good discussion:
https://www.py4u.net/discuss/1218283

Custom Rake Task aborts on Rails 4.1.5, Ruby 2.1.1p76

I have a custom rake task to evaluate project for Rails Best Practices and Brakeman as follows:
namespace :evaluate do
desc 'Evaluate project for best practices!'
task :best_practices do
path = File.expand_path("../../../", __FILE__)
sh "rails_best_practices #{path}"
end
desc 'Evaluate project with brakeman'
task :brakeman do
sh "brakeman -q -z"
end
desc 'Evaluate everything'
task :everything => [:brakeman, :best_practices]
end
Upon $ rake evaluate:everything the task completes Brakeman successfully but aborts during the rails_best_practices step with the following trace:
Command failed with status (14): [rails_best_practices /Users/admin/projects...]
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/file_utils.rb:54:in `block in create_shell_runner'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/file_utils.rb:45:in `call'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/file_utils.rb:45:in `sh'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/file_utils_ext.rb:37:in `sh'
/Users/admin/projects/bubblin/lib/tasks/security.rake:5:in `block (2 levels) in <top (required)>'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/admin/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/task.rb:199:in `each'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/task.rb:199:in `invoke_prerequisites'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/Users/admin/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/application.rb:150:in `invoke_task'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/Users/admin/.rvm/gems/ruby-2.1.1/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
/Users/admin/.rvm/gems/ruby-2.1.1/bin/rake:23:in `load'
/Users/admin/.rvm/gems/ruby-2.1.1/bin/rake:23:in `<main>'
/Users/admin/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
/Users/admin/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
I have a feeling this has something to do with my Gemfile, but unable to pinpoint the issue. What could be causing the 'block in create_shell_runner' issue for this rake task?
Thanks in advance!

state_machine draw throws uninitialized constant error

On a Rails 3.2 application
Gemfile:
gem "state_machine", "~> 1.1.2"
gem 'ruby-graphviz', :require => 'graphviz'
I installed and use with success the state_machine gem, only when I try to draw the state graph
rake state_machine:draw CLASS=Entity
it throws me this error:
** Invoke state_machine:draw (first_time)
** Execute state_machine:draw
** Invoke environment (first_time)
** Execute environment
rake aborted!
uninitialized constant StateMachine::Machine::Constants
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/gems/state_machine-1.1.2/lib/state_machine/machine.rb:1898:in `draw'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/gems/state_machine-1.1.2/lib/state_machine/machine.rb:481:in `block (2 levels) in draw'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/gems/state_machine-1.1.2/lib/state_machine/machine.rb:480:in `each_value'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/gems/state_machine-1.1.2/lib/state_machine/machine.rb:480:in `block in draw'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/gems/state_machine-1.1.2/lib/state_machine/machine.rb:472:in `each'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/gems/state_machine-1.1.2/lib/state_machine/machine.rb:472:in `draw'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/gems/state_machine-1.1.2/lib/tasks/state_machine.rb:27:in `block (2 levels) in <top (required)>'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/Users/joel/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/bin/rake:19:in `load'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#global/bin/rake:19:in `<main>'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/bin/ruby_noexec_wrapper:14:in `eval'
/Users/joel/.rvm/gems/ruby-1.9.2-p290#biowatts/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => state_machine:draw
Any leads on how to troubleshoot this one?
Dirty but works:
unless defined? StateMachine::Machine::Constants::RGV_VERSION
warn "StateMachine::Machine::Constants overriden in #{__FILE__}"
class StateMachine::Machine::Constants
RGV_VERSION = /^[ ]*ruby-graphviz \(([0-9.]+)\)/.match(`cat #{Rails.root.join 'Gemfile.lock'}`)[1]
end
end
To elaborate on tsiruu answer: in case you are using rails, just take his code and put it in an initializer
unless defined? StateMachine::Machine::Constants::RGV_VERSION
warn "StateMachine::Machine::Constants overriden in #{__FILE__}"
class StateMachine::Machine::Constants
RGV_VERSION = /^[ ]*ruby-graphviz \(([0-9.]+)\)/.match(`cat #{Rails.root.join 'Gemfile.lock'}`)[1]
end
end

Delayed Job and ActionMailer not working: "wrong number of arguments (2 for 0..1)"

I can't get DJ and ActionMailer to work for me. I always get this error:
rake aborted!
wrong number of arguments (2 for 0..1)
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/arel-3.0.2/lib/arel/expressions.rb:3:in `count'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:81:in `payload_object='
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:78:in `each'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.13/lib/active_record/base.rb:498:in `initialize'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:29:in `new'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:29:in `enqueue'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/delayed_job-3.0.5/lib/delayed/message_sending.rb:13:in `method_missing'
/Users/drale2k/Dropbox/htdocs/work/etaxi/code/etaxi/lib/tasks/mailers.rake:6:in `block (2 levels) in <top (required)>'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `eval'
/Users/drale2k/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `<main>'
This is my rake task:
namespace :mailer do
desc "Mail a list of inactive devices"
task :inactive_devices => :environment do
#devices = Device.inactive_devices
# Send only if we have inactive devices
SystemMailer.delay.inactive_devices(#devices) unless #devices.empty?
end
end
My ActionMailer class:
class SystemMailer < ActionMailer::Base
default from: "Report <system#mymail.com>"
##recipients = "Me <censored#mail.com>"
def inactive_devices(devices)
#devices = devices
mail(:to => ##recipients, :subject => "Inactive Devices")
end
end
And this is my "inactive_devices" scope on my Device model:
scope :inactive_devices, -> { where("pinged_at < ?", 24.hours.ago).where(:silent => false) }
It works fine without DJ and the delay method.
You need to add .all at the end of your where clause for it to work with delayed_job.
all should return an array, whereas where returns an ActiveRecord relation (if I've understood correctly).

Uninitialized constant error with rake db:seed and mongoid

I'm getting this error when I am trying to rake data into my application.
I have a JSON file that looks like…
[{"code": "OCH", "name": "blah", "location": "Texas, United States"},…
My db:seeds looks like:
Airport.delete_all
airport_codes = JSON.parse(File.read(Rails.root.join('db/airport_codes.json')))
airport_codes.each do |code|
Airport.create!(code)
end
And my stack trace:
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#swlv/gems/mongoid-3.0.16/lib/mongoid/railties/database.rake:13:in `block (2 levels) in <top (required)>'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/Users/nicholasshook/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/bin/rake:19:in `load'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#global/bin/rake:19:in `<main>'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#swlv/bin/ruby_noexec_wrapper:14:in `eval'
/Users/nicholasshook/.rvm/gems/ruby-1.9.3-p194#swlv/bin/ruby_noexec_wrapper:14:in `<main>'
Thanks!
Hope you have created your rake task like this
task :<rake task name> => :environment do
Airport.delete_all
airport_codes = JSON.parse(File.read(Rails.root.join('db/airport_codes.json')))
airport_codes.each do |code|
Airport.create!(code)
end
end
if this is also correct, then try to include your airport.rb to your rake file
require 'airport.rb'
, but as far as I know above rake task format should work for you
HTH

Resources