Ruby on rails 我遇到了错误';雷克流产了!NameError:未初始化的常量实值';在希罗库播种的时候
为什么Heroku忽视了我的现实 它不承认现实! 也许这也是一个存在主义的问题,但我只想为我的heroku数据库播下种子:( 我到处都在寻找可能的答案。我可以在heroku中手动创建现实对象,但不使用seeds.rb文件。类别和用户种子很好 我的确切错误Ruby on rails 我遇到了错误';雷克流产了!NameError:未初始化的常量实值';在希罗库播种的时候,ruby-on-rails,ruby,heroku,Ruby On Rails,Ruby,Heroku,为什么Heroku忽视了我的现实 它不承认现实! 也许这也是一个存在主义的问题,但我只想为我的heroku数据库播下种子:( 我到处都在寻找可能的答案。我可以在heroku中手动创建现实对象,但不使用seeds.rb文件。类别和用户种子很好 我的确切错误 D, [2017-05-21T21:18:48.820957 #4] DEBUG -- : Category Load (0.8ms) SELECT "categories".* FROM "categories" D, [2017-0
D, [2017-05-21T21:18:48.820957 #4] DEBUG -- :
Category Load (0.8ms) SELECT "categories".* FROM "categories"
D, [2017-05-21T21:18:48.826565 #4] DEBUG -- : User Load (1.1ms)
SELECT "users".* FROM "users"
rake aborted!
NameError: uninitialized constant Reality
/app/db/seeds.rb:7:in `<top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/railties
5.0.2/lib/rails/engine.rb:549:in `load_seed'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord
5.0.2/lib/active_record/tasks/database_tasks.rb:268:in `load_seed'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord
5.0.2/lib/active_record/railties/databases.rake:196:in `block (2
levels) in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in
`block in execute'
/app/vendor/bundle/ruby/2.3.0/gems/rake
12.0.0/lib/rake/task.rb:250:in`each'/app/vendor/bundle/ruby/2.3.0/gems/rake12.0.0/lib/rake/task.rb:250:i
`execute'/app/vendor/bundle/ruby/2.3.0/gems/rake
12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/monitor.rb:214:in
`mon_synchronize'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:187:in
`invoke_with_call_chain'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:180:in
`invoke'
/app/vendor/bundle/ruby/2.3.0/gems/rake
12.0.0/lib/rake/application.rb:152:in `invoke_task'
/app/vendor/bundle/ruby/2.3.0/gems/rake
12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/2.3.0/gems/rake
12.0.0/lib/rake/application.rb:108:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/rake
12.0.0/lib/rake/application.rb:108:in `block in top_level'
/app/vendor/bundle/ruby/2.3.0/gems/rake
12.0.0/lib/rake/application.rb:117:in `run_with_threads'
/app/vendor/bundle/ruby/2.3.0/gems/rake
12.0.0/lib/rake/application.rb:102:in `top_level'
/app/vendor/bundle/ruby/2.3.0/gems/rake
12.0.0/lib/rake/application.rb:80:in `block in run'
/app/vendor/bundle/ruby/2.3.0/gems/rake
12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
/app/vendor/bundle/ruby/2.3.0/gems/rake
12.0.0/lib/rake/application.rb:77:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top
(required)>'
/app/vendor/bundle/ruby/2.3.0/bin/rake:22:in `load'
/app/vendor/bundle/ruby/2.3.0/bin/rake:22:in `<top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in `load'
/app/vendor/bundle/ruby/2.3.0/gems/bundler
1.13.7/lib/bundler/cli/exec.rb:74:in `kernel_load'
/app/vendor/bundle/ruby/2.3.0/gems/bundler
1.13.7/lib/bundler/cli/exec.rb:27:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/bundler
1.13.7/lib/bundler/cli.rb:332:in `exec'
/app/vendor/bundle/ruby/2.3.0/gems/bundler
1.13.7/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/bundler
1.13.7/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in
`invoke_command'
/app/vendor/bundle/ruby/2.3.0/gems/bundler
1.13.7/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
/app/vendor/bundle/ruby/2.3.0/gems/bundler
1.13.7/lib/bundler/cli.rb:20:in `dispatch'
/app/vendor/bundle/ruby/2.3.0/gems/bundler
1.13.7/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
/app/vendor/bundle/ruby/2.3.0/gems/bundler
1.13.7/lib/bundler/cli.rb:11:in `start'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/exe/bundle:34:in
`block in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/bundler
1.13.7/lib/bundler/friendly_errors.rb:100:in `with_friendly_errors'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/exe/bundle:26:in
`<top (required)>'
/app/bin/bundle:3:in `load'
/app/bin/bundle:3:in `<main>'
Tasks: TOP => db:seed
➜ reality-checker git:(master) ✗
我的seeds.rb文件。第7行中的现实在heroku中中断
Category.destroy_all
User.destroy_all
Reality.destroy_all
## movies = Movie.create!([{ name: 'Star Wars' }, { name: 'Lord of
the Rings' }])
# Character.create!(name: 'Luke', movie: movies.first)
if Rails.env.development? || Rails.env.production?
CategorySeeder.seed!
end
reality = Reality.all
category = Category.all
user1 = User.create!(email: 'philipormorgan@gmail.com', username:
'Philip', password: '123456', admin: true)
philosophy = category[0]
love = category[1]
wisdom = category[2]
work = category[3]
traveling = category[4]
tv = category[5]
food = category[6]
anecdotes = category[7]
literature = category[8]
history = category[9]
developing = category[10]
music = category[11]
politics = category[12]
random = category[13]
Reality.create!(check: 'My philosophy is: if you can not have fun,
there is no sense in doing it-Paul Walker', user: user1, category:
philosophy )
Reality.create!(check: 'Philosophy begins in wonder-Plato', user:
user1, category: philosophy )
Reality.create!(check: 'Enjoy life, this is not a rehearsal.', user:
user1, category: philosophy )
Reality.create!(check: 'Every day may not be good, but there is
something good in every day.', user: user1, category: philosophy )
Reality.create!(check: 'Write a wise saying and your name will live
forever-anonymous', user: user1, category: philosophy )
Reality.create!(check: 'He who dies with the most toys is, nonetheless,
still dead.-anonymous', user: user1, category: philosophy )
Reality.create!(check: 'Life is about making dreams come true', user: user1, category: philosophy )
…ect
编辑
我已经重新创建了模型
我已多次重新启动heroku db
class CategorySeeder
CATEGORIES = [
{
title: "Philosophy",
description: "The world's greatest unanswered questions"
}, {
title: "Love",
description: "Your perception on love"
}, {
title: "Wisdom",
description: "Wise words from wise people"
}, {
title: "Work/School",
description: "Don't be too negative on this one ;)"
}, {
title: "Traveling",
description: "Your favorite Travel spots, and stories from traveling"
}, {
title: "TV entertainment",
description: "Movies, shows, media, and other forms of entertainment"
}, {
title: "Food/Cooking",
description: "Stories about cooking, your favorite recipes, and more"
}, {
title: "Anecdotes",
description: "Stories from your life"
}, {
title: "Literature",
description: "Favorite/least favorite books, quotes from books, and quotes form authors"
}, {
title: "History",
description: "Your favorite, or most important historical events and quotes"
}, {
title: "Web Developing",
description: "Interesting facts and stories about developer scene"
}, {
title: "Music",
description: "Favorite current, or upcoming artists songs and quotes"
}, {
title: "Politics",
description: "Your opinions on the current political environment (this could get ugly)"
}, {
title: "Random",
description: "The title speaks for itself! This could be anything"
}
].freeze
def self.seed!
CATEGORIES.each do |category_params|
title = category_params[:title]
category = Category.find_or_initialize_by(title: title)
category.assign_attributes(category_params)
category.save!
end
end
end
rails db:migrate:status
print是什么?你在应用程序中的任何位置都有第二个reality.rb文件吗?也许你的gems有?数据库:reality-Checker\u开发状态迁移ID迁移名称----------------------------------------------------------------up 20170429161956设计创建用户up 20170430201841创建类别最多20170502144325创建现实最多20170508193708设计创建视图最多20170509182739创建延迟作业最多20170509190704创建计时器最多20170511175223创建收藏夹我检查了几百次我没有看到任何重复的文件,也没有将现实视为保留字或宝石a纽约!这些都在开发中起作用。@SebastiánPalma
class Category < ApplicationRecord
include PgSearch
validates :title, presence: true, uniqueness: true
validates :description, presence: true
pg_search_scope :search_category_only, against: [:title, :description]
scope :search, ->(query) { search_category_only(query) if query.present? }
has_many :realities
has_many :timers
end
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
gem 'delayed_job_active_record'
gem 'rails', '~> 5.0.2'
gem 'pg', '~> 0.18'
gem 'puma', '~> 3.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'jquery-rails'
gem 'jbuilder', '~> 2.5'
gem 'foundation-rails'
gem 'devise'
gem 'cowsay'
gem 'pg_search'
gem 'coveralls', require: false
group :development, :test do
gem 'pry-rails'
gem 'rspec-rails'
gem 'capybara'
gem 'launchy'
gem 'factory_girl'
gem 'valid_attribute'
gem 'shoulda-matchers', require: false
end
group :development, :test do
gem 'byebug', platform: :mri
end
group :test do
gem 'coveralls', require: false
end
group :development do
gem 'listen', '~> 3.0.5'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'web-console', '>= 3.3.0'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Category.destroy_all
User.destroy_all
Reality.destroy_all
## movies = Movie.create!([{ name: 'Star Wars' }, { name: 'Lord of
the Rings' }])
# Character.create!(name: 'Luke', movie: movies.first)
if Rails.env.development? || Rails.env.production?
CategorySeeder.seed!
end
reality = Reality.all
category = Category.all
user1 = User.create!(email: 'philipormorgan@gmail.com', username:
'Philip', password: '123456', admin: true)
philosophy = category[0]
love = category[1]
wisdom = category[2]
work = category[3]
traveling = category[4]
tv = category[5]
food = category[6]
anecdotes = category[7]
literature = category[8]
history = category[9]
developing = category[10]
music = category[11]
politics = category[12]
random = category[13]
Reality.create!(check: 'My philosophy is: if you can not have fun,
there is no sense in doing it-Paul Walker', user: user1, category:
philosophy )
Reality.create!(check: 'Philosophy begins in wonder-Plato', user:
user1, category: philosophy )
Reality.create!(check: 'Enjoy life, this is not a rehearsal.', user:
user1, category: philosophy )
Reality.create!(check: 'Every day may not be good, but there is
something good in every day.', user: user1, category: philosophy )
Reality.create!(check: 'Write a wise saying and your name will live
forever-anonymous', user: user1, category: philosophy )
Reality.create!(check: 'He who dies with the most toys is, nonetheless,
still dead.-anonymous', user: user1, category: philosophy )
Reality.create!(check: 'Life is about making dreams come true', user: user1, category: philosophy )
class CategorySeeder
CATEGORIES = [
{
title: "Philosophy",
description: "The world's greatest unanswered questions"
}, {
title: "Love",
description: "Your perception on love"
}, {
title: "Wisdom",
description: "Wise words from wise people"
}, {
title: "Work/School",
description: "Don't be too negative on this one ;)"
}, {
title: "Traveling",
description: "Your favorite Travel spots, and stories from traveling"
}, {
title: "TV entertainment",
description: "Movies, shows, media, and other forms of entertainment"
}, {
title: "Food/Cooking",
description: "Stories about cooking, your favorite recipes, and more"
}, {
title: "Anecdotes",
description: "Stories from your life"
}, {
title: "Literature",
description: "Favorite/least favorite books, quotes from books, and quotes form authors"
}, {
title: "History",
description: "Your favorite, or most important historical events and quotes"
}, {
title: "Web Developing",
description: "Interesting facts and stories about developer scene"
}, {
title: "Music",
description: "Favorite current, or upcoming artists songs and quotes"
}, {
title: "Politics",
description: "Your opinions on the current political environment (this could get ugly)"
}, {
title: "Random",
description: "The title speaks for itself! This could be anything"
}
].freeze
def self.seed!
CATEGORIES.each do |category_params|
title = category_params[:title]
category = Category.find_or_initialize_by(title: title)
category.assign_attributes(category_params)
category.save!
end
end
end