Question

I have simple rails 2 composer app. I can rake migrate and seed the app locally fine and the admin user in the seed file is setup. However the db does not seed on Heroku. I get the following error (with trace when i run - heroku run rake db:setup --trace ):

** Execute db:abort_if_pending_migrations
ROLES
rake aborted!
can't convert nil into String

This is my code:

seed.rb

# This file should contain all the record creation needed to seed the database with its     default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
#   cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
#   Mayor.create(name: 'Emanuel', city: cities.first)
# Environment variables (ENV['...']) are set in the file config/application.yml.
# See http://railsapps.github.io/rails-environment-variables.html
puts 'ROLES'
YAML.load(ENV['ROLES']).each do |role|
  Role.find_or_create_by_name({ :name => role }, :without_protection => true)
  puts 'role: ' << role
end
puts 'DEFAULT USERS'
user = User.find_or_create_by_email :name => ENV['ADMIN_NAME'].dup, :email =>         ENV['ADMIN_EMAIL'].dup, :password => ENV['ADMIN_PASSWORD'].dup, :password_confirmation =>         ENV['ADMIN_PASSWORD'].dup
puts 'user: ' << user.name
user.add_role :admin
user.save!

application.yml

GMAIL_USERNAME: Your_Username
GMAIL_PASSWORD: Your_Password
ADMIN_NAME: First User
ADMIN_EMAIL: user@example.com
ADMIN_PASSWORD: changeme
ROLES: [admin, user]

I'm reasonably new to rails. The app did seed initially, but i've made some migrations and rolledback once.

Any help much appreciated.

Was it helpful?

Solution

if you trace role with a "db:reset --trace" and add "put role" like this :

YAML.load(ENV['ROLES']).each do |role| puts role

You can see that the first role is admin, but after the rake db:reset put the message "uninitialized constant Role"

So the problem is not the ENV['ROLES'] !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top