【发布时间】:2013-06-05 14:38:41
【问题描述】:
我有简单的 rails 2 composer 应用程序。我可以很好地在本地对应用程序进行 rake 迁移和播种,并且设置了种子文件中的管理员用户。但是,数据库不会在 Heroku 上播种。我收到以下错误(运行时带有跟踪 - heroku run rake db:setup --trace ):
** Execute db:abort_if_pending_migrations
ROLES
rake aborted!
can't convert nil into String
这是我的代码:
种子.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]
我对 Rails 相当陌生。该应用程序最初确实是种子,但我已经进行了一些迁移并回滚了一次。
非常感谢任何帮助。
【问题讨论】:
-
您确定设置了 ENV['ROLES'] 吗?而不是 puts 'ROLES' 尝试 puts ENV['ROLES']。
-
不应该将 ROLES 设置为
['admin', 'user']而不是[admin, user]吗? -
感谢 cmets。设法通过此评论修复使用 figaro gem - github.com/RailsApps/rails-stripe-membership-saas/issues/…
-
@Richard Margan 请将此作为答案并接受它。
标签: ruby-on-rails heroku rake seed abort