Rake tasks work locally but not on Heroku - ruby-on-rails

I have a rake task that loads data into tables of my database. I made changes recently to my schema, and migrating them to heroku appears to have worked fine. However, when I run my rake task, I get the following error message:
Don't know how to build task 'import_foursquare_response:create_records'
and a less than helpful stack trace:
heroku run rake import_foursquare_response:create_records --trace
Your version of git is 2.2.0. Which has serious security vulnerabilities.
More information here: https://blog.heroku.com/archives/2014/12/23/update_your_git_clients_on_windows_and_os_x
Running `rake import_foursquare_response:create_records --trace` attached to terminal... up, run.5353
rake aborted!
Don't know how to build task 'import_foursquare_response:create_records'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/task_manager.rb:62:in `[]'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:149:in `invoke_task'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `load'
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `<main>'
Most of the questions I've seen have pointed to syntax errors in the way people had written the actual rake task, but I can't see any problems there.
require 'four_square'
namespace :import_foursquare_response do
include FourSquare
desc "Load database with results of API calls"
task :create_records => :environment do
puts "Loading database..."
Any help is much appreciated. No data makes my app useless.

I am guessing it is just because heroku does not do any disk writing with rake tasks, please see below:
Src: https://devcenter.heroku.com/articles/rake

Related

No command "rails test" in my Ruby-on-Rails application

I've recently joined a team on a Ruby-on-Rails application, and I try to audit the tests. There were no tests, so I decided to implement them in the app.
After seeing around what was there, I have seen there were no command to run the tests available. I ran the following command:
rails --tasks
In the output, there is no command such as rails test, rails test:system. Surprisingly, I can run the command rails test with success. But the command rails test:system --trace fails with following output:
rails aborted!
Don't know how to build task 'test:system' (see --tasks)
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task_manager.rb:59:in `[]'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:159:in `invoke_task'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `each'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `block in top_level'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:125:in `run_with_threads'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:110:in `top_level'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.2.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.2.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.2.1/lib/rails/command.rb:48:in `invoke'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.2.1/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:9:in `require'
bin/rails:9:in `<main>'
I have tried running the command in a freshly created app, and I can see the available commands rails test and rails test:system.
rails --tasks
Any idea why the command rails test:system fails? Thanks.
Ruby version: 2.3.3
Rails version: 5.2.0
EDIT:
I'm using MiniTest
To run all specs in a single go:
rspec
To execute a specific test file:
rspec <path to the file> # rspec spec/controllers/mytest_spec.rb
Use --format documentation for a formatted output.
Prepend bundle exec if rspec throws a dependency error.

How to use the attach gem in rails 5

My environment:
Ruby 2.4.1
Rails 5.1.4
I am trying to use the attach gem, written by the person who also wrote this article https://atech.blog/atech/file-attachments-in-rails-tutorial.
When I run the bundle install it installs attach gem, version 1.0.2
Then when I try to run the rake command I get an error saying it does not know how to build the task.
rake attach:install:migrations --trace
rake aborted!
Don't know how to build task 'attach:install:migrations' (see --tasks)
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/task_manager.rb:59:in `[]'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:159:in `invoke_task'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:116:in `each'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:116:in `block in top_level'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:125:in `run_with_threads'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:110:in `top_level'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:83:in `block in run'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:186:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:80:in `run'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.4.1/bin/rake:23:in `load'
/usr/local/rvm/gems/ruby-2.4.1/bin/rake:23:in `<main>'
/usr/local/rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `<main>'
Any ideas on what the error is? I am wondering if I am missing a required gem to make it work. The link to the attach documentation is https://github.com/adamcooke/attach
There are no rake tasks defined in this repo.
After you run bundle install, you can get a list of rake tasks by running rake -P (rake -T shows tasks with descriptions). You'll see that attach:install:migrations is not there.
Why not try using paperclip?

rake db:load doesn't work

I'm totaly noob in Ruby, and I can't execute the command rake db:load. Sorry for stupid question, but I need help.
The same error is thrown on rake db:seed
root#root:/var/www/dir# rake db:load --trace
rake aborted!
Don't know how to build task 'db:load'
/usr/lib/ruby/gems/1.8/gems/rake-10.0.4/lib/rake/task_manager.rb:49:in `[]'
/usr/lib/ruby/gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:142:in `invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:101:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:101:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/usr/lib/ruby/gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:73:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-10.0.4/bin/rake:33
/usr/bin/rake:23:in `load'
/usr/bin/rake:23
There's two issues with this project. First of all it lacks a Javascript runtime. You can solve this by adding
gem 'execjs'
gem 'therubyracer'
to the GemFile and rerunning
bundle install
The second problem is that there is no db:load task specified. Looking at the code you want to use
bundle exec rake db:schema:load
That should work.

delayed job's task problem with rails 2.3.5 [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I am using rubygem delayed job but not able to run rake task successfully. I took reference of https://github.com/collectiveidea/delayed_job/tree/v2.0. BTW, i am using bundler.
#Gemfile
gem 'delayed_job', '~>2.0.4'
#Rake file
begin
gem 'delayed_job', '~>2.0.4'
require 'delayed/tasks'
rescue LoadError
STDERR.puts "Run `bundle` to install delayed_job"
end
While running rake jobs:work --trace, it displays below error
rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+)
** Invoke jobs:work (first_time)
** Invoke merb_env (first_time)
** Execute merb_env
** Invoke environment (first_time)
** Execute environment
** Execute jobs:work
rake aborted!
Anonymous modules have no name to be referenced by
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:585:in `to_constant_name'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:391:in `qualified_name_for'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:104:in `rescue in const_missing'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:94:in `const_missing'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/delayed_job-2.0.6/lib/delayed/tasks.rb:13:in `block (2 levels) in '
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/gems/rake-0.9.2/bin/rake:32:in `'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/bin/rake:19:in `load'
/Users/me/.rvm/gems/ruby-1.9.2-p180#suga/bin/rake:19:in `'
Tasks: TOP => jobs:work
I tried Delayed Job Rake Task Failing but it didn't solve my problem.
Can anyone describes what is happening here?
Thanks.
Ah! Debugging DJ is a pain in the you know what.
This error message:
=> Aonymous modules have no name to be referenced by
Means that you have spelled one of your models incorrectly.
For example: Categorizatoin instead of Categorizatoin.
So go through your Models in DJ and check your spelling on all of your models.
I really don't understand why DJ won't work properly using gem in 2.3 of rails version.Make sure you have installed plugin instead for gem and then do as the documetation says. I hope this won't give you anonymous module problem.

Rake db:migration aborted

I've got a unfinished project that a developer just didn't finish and didn't leave any documentation about the installation process. I've downloaded the production directory to my windows machine (running InstantRails 2), I created the databases as required in the database.yml and I tried to run the rake:db:migrate --trace but I'm receiving the following error message:
(in D:/projects/broke2)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
uninitialized constant Admin
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:279:in `load_missing_constant'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:468:in `const_missing'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:480:in `const_missing'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/inflector.rb:285:in `constantize'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/inflector.rb:284:in `each'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/inflector.rb:284:in `constantize'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/string/inflections.rb:143:in `constantize'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/migration.rb:481:in `migrations'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/mysql_adapter.rb:15:in `inject'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/migration.rb:465:in `each'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/migration.rb:465:in `inject'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/migration.rb:465:in `migrations'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/migration.rb:431:in `migrate'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/migration.rb:373:in `up'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/migration.rb:356:in `migrate'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/tasks/databases.rake:99
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `call'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `execute'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `each'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `execute'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in `invoke_with_call_chain'
D:/InstantRails-2.0-win/ruby/lib/ruby/1.8/monitor.rb:242:in `synchronize'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in `invoke_with_call_chain'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in `invoke'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in `invoke_task'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `each'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `standard_exception_handling'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1991:in `top_level'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in `run'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `standard_exception_handling'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in `run'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/bin/rake:31
D:/InstantRails-2.0-win/ruby/bin/rake:19:in `load'
D:/InstantRails-2.0-win/ruby/bin/rake:19
I'm a regular Rails developer (it's not my first app) but I never saw this error and I don't have a clue where to start to debug.
Sometimes Rails will throw this error if there's a syntax error where Admin is defined.
Try looking for admin.rb and make sure that it parses.
Also, you may want to try running the migrations one at a time (rake db:migrate VERSION=1, etc.) to see if that helps you track down which migration causes the error, or if it is a problem simply booting the application.
I suspect you had a migration that created a table and added some data using a model. Later in the project the model got renamed or removed (as did the table maybe?). As the model no longer existed the migrations failed to run, but no one noticed as by that point they were only running a few migrations at a time, not from a clean database.
The lesson here ... if you rename models or tables (or update their validations and fields) then check your migrations run from scratch as well on the current production version.
I'd say your problem is in the uninitialized constant Admin part of your migration issue. Have you tried finding where Admin is initialized and including the path to that wherever you're using it? (Also, what's the contents of the rake task you're running?)
It don't points me where i have a Admin constant. There is a way to check at least where should I look? my models, my controllers, etc?
rake db:migrate VERSION=1, gives me a error already. As I told you, am I just trying to finish a project unfinished by another guy.
How can i do a migration file per file?
Regards,
Victor
You can try loading the schema all at once instead of executing each migration:
rake db:schema:load
As RichH said there might have been a change to the schema not reflected in the migrations

Resources