Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 耙子种子流产了!不能';t将nil转换为字符串_Ruby On Rails_Heroku_Rake_Seed_Abort - Fatal编程技术网

Ruby on rails 耙子种子流产了!不能';t将nil转换为字符串

Ruby on rails 耙子种子流产了!不能';t将nil转换为字符串,ruby-on-rails,heroku,rake,seed,abort,Ruby On Rails,Heroku,Rake,Seed,Abort,我有一个简单的rails 2 composer应用程序。我可以耙迁移和种子的应用程序在本地罚款和管理用户在种子文件中设置。但是db不会在Heroku上播种。我得到以下错误(当我运行-heroku run rake db:setup--trace时使用trace): 这是我的代码: seed.rb # This file should contain all the record creation needed to seed the database with its default v

我有一个简单的rails 2 composer应用程序。我可以耙迁移和种子的应用程序在本地罚款和管理用户在种子文件中设置。但是db不会在Heroku上播种。我得到以下错误(当我运行-heroku run rake db:setup--trace时使用trace):

这是我的代码:

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!
我对rails相当陌生。该应用程序最初确实启动了,但我进行了一些迁移并回滚了一次

非常感谢您的帮助。

如果您使用“db:reset--trace”跟踪角色并添加如下“put role”:

YAML.load(环境['ROLES'])。每个do | role| 扮演角色

您可以看到第一个角色是admin,但在rake db:reset之后,会显示消息“uninitialized constant role”


所以问题不在于ENV['ROLES']

您确定已设置环境['ROLES']吗?请尝试使用puts ENV['ROLES'],而不是puts'ROLES'。不应该将角色设置为
['admin','user']
而不是
[admin,user]
?谢谢您的评论。通过此评论成功修复了使用figaro gem的问题-@Richard Margan请将此作为答案并接受它。
# 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!
GMAIL_USERNAME: Your_Username
GMAIL_PASSWORD: Your_Password
ADMIN_NAME: First User
ADMIN_EMAIL: user@example.com
ADMIN_PASSWORD: changeme
ROLES: [admin, user]