rails aborted "Don't know how to build task 'AdminUser.create!()" - ruby-on-rails

I recently added the gem Active Admin to my rails applicaction (using rails 5.2.6), I got it to work with the default admin and it's working as intended. But I'm unable to add new admins with AdminUser.create!(email: "admin#gmail.com", password: "password", password_confirmation: "password") as I get the rails aborted error and then Don't know how to build task 'AdminUser.create!(email: "admin#gmail.com", password: "password", password_confirmation: "password").
I already tried using rails db:migrate and running my seeds.
Also I am using the devise gem.
Full trace:
rails aborted!
Don't know how to build task 'AdminUser.create!(email: example#gmail.com, password: password, password_confirmation: password)' (See the list of available tasks with `rails --tasks`)
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/task_manager.rb:59:in `[]'
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:159:in `invoke_task'
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
/var/lib/gems/2.7.0/gems/railties-5.2.6/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
/var/lib/gems/2.7.0/gems/railties-5.2.6/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/var/lib/gems/2.7.0/gems/railties-5.2.6/lib/rails/command.rb:48:in `invoke'
/var/lib/gems/2.7.0/gems/railties-5.2.6/lib/rails/commands.rb:18:in `<main>'
/var/lib/gems/2.7.0/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/var/lib/gems/2.7.0/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/var/lib/gems/2.7.0/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/var/lib/gems/2.7.0/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/var/lib/gems/2.7.0/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/home/magus/Desktop/Proyecto ing software/grupo-56/bin/rails:9:in `<top (required)>'
/var/lib/gems/2.7.0/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `load'
/var/lib/gems/2.7.0/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `call'
/var/lib/gems/2.7.0/gems/spring-2.1.1/lib/spring/client/command.rb:7:in `call'
/var/lib/gems/2.7.0/gems/spring-2.1.1/lib/spring/client.rb:30:in `run'
/var/lib/gems/2.7.0/gems/spring-2.1.1/bin/spring:49:in `<top (required)>'
/var/lib/gems/2.7.0/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `load'
/var/lib/gems/2.7.0/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `<top (required)>'
/usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'
/usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'
/home/magus/Desktop/Proyecto ing software/grupo-56/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
As I said before, all the other ActiveAdmin functionalities are working as intended, it's just that I can't create new admins.
What am I doing wrong/could have forgotten to do?
Thanks in advance.

There are several ways to add that admin into the database:
rails console - Just open the console and execute AdminUser.create!(...).
seeds.rb - Open the db/seeds.rb file and paste AdminUser.create!(...). Then run rake db:seed. Note that running rake db:seed multiple times will create that admin multiple times - it's best you have some sort of validations or use AdminUser.find_or_create_by(...) instead.
rake task - create a rake file in lib/tasks, name is not important but it should end in .rake (ex: update.rake)
task :add_admin do
AdminUser.find_or_create_by(email: "admin#gmail.com", password: "password", password_confirmation: "password")
end
Run it with rake add_admin.
If you want that admin only for yourself, your local machine, use the console approach, otherwise pick the other two but make sure the rake tasks are idempotent.

Related

Convention for running rails seeds

Rails 7
Per the tutorial I am following, to run specific seed files, I am supposed to create the following folder structure:
/db/seeds
And in that folder, I place my seed file:
/db/seeds/authors.seeds.rb
In /db/seeds/authors.seeds.rb, I have:
authors = [
{"first" => "John", "last" => "Doe"},
{"first" => "Jane", "last" => "Doe"}
]
authors.each do |a|
Author.create!(a)
end
When I try to run it as:
rails db:seeds:authors --trace
I get the following error:
rails aborted!
Don't know how to build task 'db:seeds:authors' (See the list of available tasks with `rails --tasks`)
.../rake-13.0.6/lib/rake/task_manager.rb:59:in `[]'
.../rake-13.0.6/lib/rake/application.rb:159:in `invoke_task'
.../rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
.../rake-13.0.6/lib/rake/application.rb:116:in `each'
.../rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
.../rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
.../rake-13.0.6/lib/rake/application.rb:110:in `top_level'
.../railties-7.0.2.2/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
.../rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
.../railties-7.0.2.2/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
.../rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
.../railties-7.0.2.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
.../railties-7.0.2.2/lib/rails/command.rb:51:in `invoke'
.../railties-7.0.2.2/lib/rails/commands.rb:18:in `<main>'
.../bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
.../bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
bin/rails:4:in `<main>'
I checked and the table is there.
Edit:
When I put copy the contents of /db/seeds/authors.seeds.rb to /db/seeds.rb and then run:
rake db:seed
It executes properly.
Any ideas?
I think you just need to run rake db:seed only in your terminal, remove the authors keyword

no migration via terminal

I can't migrate new columns in my database via the terminal and RoR.
I only get the first step:
**$ rails g migration add_online_to_posts online:boolean**
Running via Spring preloader in process 13406
invoke active_record
create db/migrate/20170808141302_add_online_to_posts.rb
Afterwards nothing works:
**$ rails db:migrate**
rails aborted!
ActiveRecord::DuplicateMigrationVersionError:
Multiple migrations have the version number 20170725122210.
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/migration.rb:1257:in `validate'
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/migration.rb:1123:in `initialize'
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/migration.rb:1007:in `new'
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/migration.rb:1007:in `up'
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/migration.rb:985:in `migrate'
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/home/projets/RoR_formation/vendor/bundle/gems/railties-5.1.2/lib/rails/commands/rake/rake_command.rb:21:in `block in perform'
/home/projets/RoR_formation/vendor/bundle/gems/railties-5.1.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/home/projets/RoR_formation/vendor/bundle/gems/railties-5.1.2/lib/rails/command.rb:46:in `invoke'
/home/projets/RoR_formation/vendor/bundle/gems/railties-5.1.2/lib/rails/commands.rb:16:in `<top (required)>'
/home/projets/RoR_formation/bin/rails:9:in `require'
/home/projets/RoR_formation/bin/rails:9:in `<top (required)>'
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
/home/projets/RoR_formation/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate
I can handle columns via the IDE:
But when I do :
**$ Status Migration ID Migration Name**
up 20170725122210 Create posts table
up 20170726082500 Rename post title to intitule
up 20170728143925 Create categories
up 20170807110617 ********** NO FILE **********
down 20170808113533 Add slug to posts
You've already run a migration with the prefix 20170725122210 (and it looks like you may have also deleted it). For a quick fix, change your newest migration to 20170725122211 (or any other number that isn't in your schema migrations table). You may also want to run rails db:schema:dump and inspect the output of db/schema.rb for tables that are not present in your migrations.

Sending emails during Capistrano deployment using Rails 5, Ruby 2.4, and Capistrano 3

Capistrano 3.7.2, Rails 5.0.2, and Ruby 2.4.0 to be specific. The error I get occurs after Execute load:defaults:
** Execute load:defaults
cap aborted!
NameError: uninitialized constant ActiveSupport::Rescuable
/Users/username/.rvm/gems/ruby-2.4.0/gems/actionmailer-5.0.2/lib/action_mailer/rescuable.rb:6:in `<module:Rescuable>'
/Users/username/.rvm/gems/ruby-2.4.0/gems/actionmailer-5.0.2/lib/action_mailer/rescuable.rb:4:in `<module:ActionMailer>'
/Users/username/.rvm/gems/ruby-2.4.0/gems/actionmailer-5.0.2/lib/action_mailer/rescuable.rb:1:in `<top (required)>'
/Users/username/.rvm/gems/ruby-2.4.0/gems/actionmailer-5.0.2/lib/action_mailer/base.rb:8:in `require'
/Users/username/.rvm/gems/ruby-2.4.0/gems/actionmailer-5.0.2/lib/action_mailer/base.rb:8:in `<top (required)>'
/Users/username/rails_5_test_app/config/deploy/notify/cap_mailer.rb:5:in `require'
/Users/username/rails_5_test_app/config/deploy/notify/cap_mailer.rb:5:in `<top (required)>'
config/deploy.rb:4:in `require'
config/deploy.rb:4:in `<top (required)>'
/Users/username/.rvm/gems/ruby-2.4.0/gems/capistrano-3.7.2/lib/capistrano/setup.rb:27:in `load'
/Users/username/.rvm/gems/ruby-2.4.0/gems/capistrano-3.7.2/lib/capistrano/setup.rb:27:in `block (3 levels) in <top (required)>'
/Users/username/.rvm/gems/ruby-2.4.0/gems/capistrano-3.7.2/lib/capistrano/configuration/variables.rb:32:in `untrusted!'
/Users/username/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/delegate.rb:83:in `method_missing'
/Users/username/.rvm/gems/ruby-2.4.0/gems/capistrano-3.7.2/lib/capistrano/setup.rb:26:in `block (2 levels) in <top (required)>'
/Users/username/.rvm/gems/ruby-2.4.0#global/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute'
/Users/username/.rvm/gems/ruby-2.4.0#global/gems/rake-12.0.0/lib/rake/task.rb:250:in `each'
/Users/username/.rvm/gems/ruby-2.4.0#global/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute'
/Users/username/.rvm/gems/ruby-2.4.0#global/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain'
/Users/username/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
/Users/username/.rvm/gems/ruby-2.4.0#global/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain'
/Users/username/.rvm/gems/ruby-2.4.0#global/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
/Users/username/.rvm/gems/ruby-2.4.0#global/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task'
/Users/username/.rvm/gems/ruby-2.4.0#global/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/Users/username/.rvm/gems/ruby-2.4.0#global/gems/rake-12.0.0/lib/rake/application.rb:108:in `each'
/Users/username/.rvm/gems/ruby-2.4.0#global/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level'
/Users/username/.rvm/gems/ruby-2.4.0#global/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads'
/Users/username/.rvm/gems/ruby-2.4.0#global/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level'
/Users/username/.rvm/gems/ruby-2.4.0#global/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run'
/Users/username/.rvm/gems/ruby-2.4.0#global/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
/Users/username/.rvm/gems/ruby-2.4.0#global/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
/Users/username/.rvm/gems/ruby-2.4.0/gems/capistrano-3.7.2/lib/capistrano/application.rb:14:in `run'
/Users/username/.rvm/gems/ruby-2.4.0/gems/capistrano-3.7.2/bin/cap:3:in `<top (required)>'
/Users/username/.rvm/gems/ruby-2.4.0/bin/cap:22:in `load'
/Users/username/.rvm/gems/ruby-2.4.0/bin/cap:22:in `<main>'
/Users/username/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `eval'
/Users/username/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => staging
I'm about to start upgrading my Rails 4 apps to Rails 5, and decided to do a small test app to make sure all my gems are working. Everything is fine, except for the code I've been using since Rails 2 to send emails during a Capistrano deploy, which results in this error when I try to require or load the mailer code; line 4 of deploy.rb is the require. If I comment that out and set a flag to not send an email, the deploy works perfectly.
The mailer code (based off of something posted by Mislav Marohnić years ago):
cap_mailer.rb:
require "action_mailer"
yaml_config = File.read("config/email.yml")
email_config = YAML.load(yaml_config)
ActionMailer::Base.delivery_method = email_config['delivery_method'] # currently set to :smtp
ActionMailer::Base.smtp_settings = {
address: email_config['smtp_settings']['address'],
port: email_config['smtp_settings']['port'],
notify_emails: email_config['notify_emails']
}
ActionMailer::Base.view_paths = File.dirname(__FILE__)
class CapMailer < ActionMailer::Base
default :from => 'App Deployment <app_deploy#my.org>'
def deploy_notification(cap_vars)
#now = Time.now
set :body, ENV['comment']
mail(:to => fetch(:notify_emails),
:subject => "#{fetch(:human_readable_application_name)} - Changes to application on #{fetch(:stage)} server at #{fetch(:host)}"
)
end
def test_email
#now = Time.now
mail(:to => "developer#my.org",
:subject => "#{fetch(:human_readable_application_name)} - Capistrano test email #{#now.strftime("on %m/%d/%Y at %I:%M %p")}"
)
end
end
All I can dig up online are references to very similar mailing set-ups (e.g. https://gist.github.com/johnthethird/955917) that were written for older versions of everything. There are several gems written to send mail during Capistrano deploys, but they have the same problem with being really old (capistrano-notifier, capistrano_mailer).
So at this point I'm stuck. Googling NameError: uninitialized constant ActiveSupport::Rescuable suggested maybe this is a config problem, but I don't know what to look for there. ActiveSupport::Rescuable IS there in my Rails installation; I double-checked. Any ideas would be appreciated.
Looks like you need to load ActiveSupport first, like this:
require "active_support"
require "action_mailer"

Rails 4.2 Using Heart Seed to import data on Heroku

I am using heartseed gem to import data in my rails application. It is working fine in my local machine.
When I try to do the same on heroku I get the following error.
** Invoke db:seed (first_time)
** Execute db:seed
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
rake aborted!
require TABLES or CATALOGS if production
/app/vendor/bundle/ruby/2.0.0/gems/heart_seed-0.1.0/lib/heart_seed/db_seed.rb:73:in `import_all'
/app/db/seeds.rb:10:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `block in load'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.3/lib/rails/engine.rb:547:in `load_seed'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.3/lib/active_record/tasks/database_tasks.rb:250:in `load_seed'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.3/lib/active_record/railties/databases.rake:180:in `block (2 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.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>'
Tasks: TOP => db:seed
On another note - I have tried http://railscasts.com/episodes/396-importing-csv-and-excel Roo for file upload and add data to database and it does not seem to work for me for rails 4.2 - can anyone guide me there as well pls?
It's always worth checking out the source code, this is the line that is throwing the error:
https://github.com/sue445/heart_seed/blob/master/lib/heart_seed/db_seed.rb#L73
It looks like you need to set the TABLES and CATALOGS environment variables to make this work in production (so on Heroku). You can set environment variables for your Heroku application with heroku config:set TABLES=... etc.
The Railscast you linked to is pretty old so there is a fair chance that things will have moved on a bit since then. The Roo gem seems to be actively maintained so you will probably find up-to-date info in the README at https://github.com/roo-rb/roo .
Generally whenever I have had to import data from a spreadsheet I've saved the file as CSV and then written a simple Ruby script or Rake file that just uses the CSV library (http://docs.ruby-lang.org/en/2.2.0/CSV.html) to do the import.

Deploy Rails 2.3.16 application on Heroku, try to migrate database, rake aborted! cannot load such file -- iconv

I am trying to deploy a copy of a Rails 2.3.16 application on Heroku. I pushed the application, and added a PostgreSQL database.
heroku run rake db:migrate
rake aborted!
cannot load such file --iconv
Apparently all new applications will run in ruby 2.0.0, and I have been having a lot of trouble managing versions recently. The old applications run in whatever version they were, which is 1.9.2. Maybe that is related. I looked for a long time, and found things such as:
Ruby 2.0 iconv replacement
in `require': no such file to load -- iconv (LoadError)
I tried gem install iconv
This site doesn't help, or maybe I don't understand what to do:
https://rvm.io/packages/iconv
rvm autolibs rvm_pkg did nothing. rvm autolibs enable didn't help.
This site seemed to say something completely different even though it linked to https://rvm.io/packages/iconv:
http://bullrico.com/2012/09/04/cannot-load-such-file-iconv/
I did:
rvm reinstall 1.9.2-p290 --with-iconv-dir=$rvm_path/usr
At least 2 things failed in that, and iconv issue is not resolved:
Error running 'env GEM_PATH=/Users/RedApple/.rvm/gems/ruby-1.9.2-p290:/Users/RedApple/.rvm/gems/ruby-1.9.2-p290#global:/Users/RedApple/.rvm/gems/ruby-1.9.2-p290:/Users/RedApple/.rvm/gems/ruby-1.9.2-p290#global GEM_HOME=/Users/RedApple/.rvm/gems/ruby-1.9.2-p290 /Users/RedApple/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -d /Users/RedApple/.rvm/src/rubygems-2.1.4/setup.rb',
please read /Users/RedApple/.rvm/log/1379705294_ruby-1.9.2-p290/rubygems.install.log
Installation of rubygems did not complete successfully.
Error running '__rvm_with ruby-1.9.2-p290 /Users/RedApple/.rvm/scripts/gemsets pristine',
please read /Users/RedApple/.rvm/log/1379705294_ruby-1.9.2-p290/gemset.pristine-ruby-1.9.2-p290.log
heroku run rake db:migrate
rake aborted!
cannot load such file -- iconv
I don't have time to reprogram the 2.3.16 application into 3 or 4 if that is required. I don't even know what iconv is. What is the easiest way to get rid of this error?
Edit:
I put this in the Gemfile and redeployed:
ruby '1.9.2'
I don't know if it is progress, but now a new error:
heroku run rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
bad URI(is not URI?):
/app/vendor/ruby-1.9.2/lib/ruby/1.9.1/uri/common.rb:156:in `split'
/app/vendor/ruby-1.9.2/lib/ruby/1.9.1/uri/common.rb:174:in `parse'
/app/vendor/ruby-1.9.2/lib/ruby/1.9.1/uri/common.rb:628:in `parse'
/app/config/initializers/redis.rb:1:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-2.3.16/lib/active_support/dependencies.rb:173:in `load'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-2.3.16/lib/active_support/dependencies.rb:173:in `load_with_new_constant_marking'
/app/vendor/bundle/ruby/1.9.1/gems/rails-2.3.16/lib/initializer.rb:622:in `block in load_application_initializers'
/app/vendor/bundle/ruby/1.9.1/gems/rails-2.3.16/lib/initializer.rb:621:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rails-2.3.16/lib/initializer.rb:621:in `load_application_initializers'
/app/vendor/bundle/ruby/1.9.1/gems/rails-2.3.16/lib/initializer.rb:176:in `process'
/app/vendor/bundle/ruby/1.9.1/gems/rails-2.3.16/lib/initializer.rb:113:in `run'
/app/config/environment.rb:11:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-2.3.16/lib/active_support/dependencies.rb:182:in `require'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-2.3.16/lib/active_support/dependencies.rb:182:in `block in require'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-2.3.16/lib/active_support/dependencies.rb:547:in `new_constants_in'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-2.3.16/lib/active_support/dependencies.rb:182:in `require'
/app/vendor/bundle/ruby/1.9.1/gems/rails-2.3.16/lib/tasks/misc.rake:4:in `block in <top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain'
/app/vendor/ruby-1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:607:in `block in invoke_prerequisites'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:604:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:596:in `block in invoke_with_call_chain'
/app/vendor/ruby-1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/bin/rake:31:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `load'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `<main>'
Edit:
I didn't read the error message thoroughly, and missed this line:
/app/config/initializers/redis.rb:1:in `<top (required)>'
I commented out these lines, since I don't need Redis yet:
# uri = URI.parse( ENV[ "REDISTOGO_URL" ] )
# REDIS = Redis.new( :host => uri.host, :port => uri.port, :password => uri.password )
heroku run rake db:migrate finally worked.
All of that, and it seems the main problem was solved by adding this line to the Gemfile:
ruby '1.9.2'
Lesson learned: If you have an old application that needs to be redeployed for some other purpose on Heroku, you need to specify the ruby version in the Gemfile.

Resources