我正在尝试运行rake db:seed
或bundle exec rake db:seed
,并且会返回此错误。
rake aborted!
Errno::ECONNREFUSED: Connection refused - {:data=>"<?xml version=\"1.0\" encoding=\"UTF-8\"?><add><doc><field name=\"id\">Topic 3</field><field name=\"type\">Topic</field><field name=\"type\">ActiveRecord::Base</field><field name=\"class_name\">Topic</field><field name=\"topic_text\">Astronomy</field></doc></add>", :headers=>{"Content-Type"=>"text/xml"}, :method=>:post, :params=>{:wt=>:ruby}, :query=>"wt=ruby", :path=>"update", :uri=>#<URI::HTTP http://localhost:8982/solr/default/update?wt=ruby>, :open_timeout=>nil, :read_timeout=>nil, :retry_503=>nil, :retry_after_limit=>nil}
(eval):2:in `post'
/Users/lewisfrost/frostfires/db/seeds.rb:10:in `<top (required)>'
Errno::ECONNREFUSED: Connection refused - connect(2) for "localhost" port 8982
(eval):2:in `post'
/Users/lewisfrost/frostfires/db/seeds.rb:10:in `<top (required)>'
Tasks: TOP => db:seed
我的seeds.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)
Topic.create!(topic: 'Astronomy') unless Topic.where(topic: 'Astronomy').present?
Topic.create!(topic: 'Backpacking') unless Topic.where(topic: 'Backpacking').present?
Topic.create!(topic: 'BASE jumping') unless Topic.where(topic: 'BASE jumping').present?
Topic.create!(topic: 'Baseball') unless Topic.where(topic: 'Baseball').present?
Topic.create!(topic: 'Basketball') unless Topic.where(topic: 'Basketball').present?
Topic.create!(topic: 'Beekeeping') unless Topic.where(topic: 'Beekeeping').present?
Topic.create!(topic: 'Bird watching') unless Topic.where(topic: 'Bird watching').present?
Topic.create!(topic: 'Cycling') unless Topic.where(topic: 'Cycling').present?
Topic.create!(topic: 'Driving') unless Topic.where(topic: 'Driving').present?
Topic.create!(topic: 'Fishing') unless Topic.where(topic: 'Fishing').present?
Topic.create!(topic: 'Football') unless Topic.where(topic: 'Football').present?
Topic.create!(topic: 'Flying') unless Topic.where(topic: 'Flying').present?
Topic.create!(topic: 'Jogging') unless Topic.where(topic: 'Jogging').present?
Topic.create!(topic: 'Kayaking') unless Topic.where(topic: 'Kayaking').present?
Topic.create!(topic: 'Kiteboarding') unless Topic.where(topic: 'Kiteboarding').present?
Topic.create!(topic: 'Motor sports') unless Topic.where(topic: 'Motor sports').present?
Topic.create!(topic: 'Mountain biking') unless Topic.where(topic: 'Mountain biking').present?
Topic.create!(topic: 'Mountaineering') unless Topic.where(topic: 'Mountaineering').present?
Topic.create!(topic: 'Photography') unless Topic.where(topic: 'Photography').present?
Topic.create!(topic: 'Rafting') unless Topic.where(topic: 'Rafting').present?
Topic.create!(topic: 'Rock climbing') unless Topic.where(topic: 'Rock climbing').present?
Topic.create!(topic: 'Running') unless Topic.where(topic: 'Running').present?
Topic.create!(topic: 'Sailing') unless Topic.where(topic: 'Sailing').present?
Topic.create!(topic: 'Scuba Diving') unless Topic.where(topic: 'Scuba Diving').present?
Topic.create!(topic: 'Shooting') unless Topic.where(topic: 'Shooting').present?
Topic.create!(topic: 'Skateboarding') unless Topic.where(topic: 'Skateboarding').present?
Topic.create!(topic: 'Skiing') unless Topic.where(topic: 'Skiing').present?
Topic.create!(topic: 'Skydiving') unless Topic.where(topic: 'Skydiving').present?
Topic.create!(topic: 'Surfing') unless Topic.where(topic: 'Surfing').present?
Topic.create!(topic: 'Snowboarding') unless Topic.where(topic: 'Snowboarding').present?
Topic.create!(topic: 'Swimming') unless Topic.where(topic: 'Swimming').present?
Place.create!(place: 'Bangkok' , name:'Bangkok') unless Place.where(place: 'Bangkok' , name:'Bangkok').present?
Place.create!(place: 'London' , name:'London') unless Place.where(place: 'London' , name:'London').present?
Place.create!(place: 'Paris' , name:'Paris') unless Place.where(place: 'Paris' , name:'Paris').present?
Place.create!(place: 'Singapore' , name:'Singapore') unless Place.where(place: 'Singapore' , name:'Singapore').present?
Place.create!(place: 'New York' , name:'New York') unless Place.where(place: 'New York' , name:'New York').present?
Place.create!(place: 'Istanbul' , name:'Istanbul') unless Place.where(place: 'Istanbul' , name:'Istanbul').present?
Place.create!(place: 'Dubai' , name:'Dubai') unless Place.where(place: 'Dubai' , name:'Dubai').present?
Place.create!(place: 'Kuala Lumpur' , name:'Kuala Lumpur') unless Place.where(place: 'Kuala Lumpur' , name:'Kuala Lumpur').present?
Place.create!(place: 'Hong Kong' , name:'Hong Kong') unless Place.where(place: 'Hong Kong' , name:'Hong Kong').present?
Place.create!(place: 'Barcelona' , name:'Barcelona') unless Place.where(place: 'Barcelona' , name:'Barcelona').present?
Place.create!(place: 'Orlando' , name:'Orlando') unless Place.where(place: 'Orlando' , name:'Orlando').present?
Place.create!(place: 'Washington DC' , name:'Washington DC') unless Place.where(place: 'Washington DC' , name:'Washington DC').present?
Place.create!(place: 'Honolulu' , name:'Honolulu') unless Place.where(place: 'Honolulu' , name:'Honolulu').present?
Place.create!(place: 'Boston' , name:'Boston') unless Place.where(place: 'Boston' , name:'Boston').present?
Place.create!(place: 'Chicago' , name:'Chicago') unless Place.where(place: 'Chicago' , name:'Chicago').present?
Place.create!(place: 'Las Vegas' , name:'Las Vegas') unless Place.where(place: 'Las Vegas' , name:'Las Vegas').present?
Place.create!(place: 'San Francisco' , name:'San Francisco') unless Place.where(place: 'San Francisco' , name:'San Francisco').present?
Place.create!(place: 'Miami' , name:'Miami') unless Place.where(place: 'Miami' , name:'Miami').present?
Place.create!(place: 'Los Angeles' , name:'Los Angeles') unless Place.where(place: 'Los Angeles' , name:'Los Angeles').present?
Place.create!(place: 'New York City' , name:'New York City') unless Place.where(place: 'New York City' , name:'New York City').present?
Place.create!(place: 'France' , name:'France') unless Place.where(place: 'France' , name:'France').present?
Place.create!(place: 'United States' , name:'United States') unless Place.where(place: 'United States' , name:'United States').present?
Place.create!(place: 'China' , name:'China') unless Place.where(place: 'China' , name:'China').present?
Place.create!(place: 'Spain' , name:'Spain') unless Place.where(place: 'Spain' , name:'Spain').present?
Place.create!(place: 'Italy' , name:'Italy') unless Place.where(place: 'Italy' , name:'Italy').present?
Place.create!(place: 'Turkey' , name:'Turkey') unless Place.where(place: 'Turkey' , name:'Turkey').present?
Place.create!(place: 'United Kingdom' , name:'United Kingdom') unless Place.where(place: 'United Kingdom' , name:'United Kingdom').present?
Place.create!(place: 'Germany' , name:'Germany') unless Place.where(place: 'Germany' , name:'Germany').present?
Place.create!(place: 'Russian Federation' , name:'Russian Federation') unless Place.where(place: 'Russian Federation' , name:'Russian Federation').present?
Place.create!(place: 'Malaysia' , name:'Malaysia') unless Place.where(place: 'Malaysia' , name:'Malaysia').present?
Place.create!(place: 'Mexico' , name:'Mexico') unless Place.where(place: 'Mexico' , name:'Mexico').present?
Place.create!(place: 'Austria' , name:'Austria') unless Place.where(place: 'Austria' , name:'Austria').present?
Place.create!(place: 'Ukraine' , name:'Ukraine') unless Place.where(place: 'Ukraine' , name:'Ukraine').present?
Place.create!(place: 'Thailand' , name:'Thailand') unless Place.where(place: 'Thailand' , name:'Thailand').present?
Place.create!(place: 'Saudi Arabia' , name:'Saudi Arabia') unless Place.where(place: 'Saudi Arabia' , name:'Saudi Arabia').present?
Place.create!(place: 'Greece' , name:'Greece') unless Place.where(place: 'Greece' , name:'Greece').present?
Place.create!(place: 'Canada' , name:'Canada') unless Place.where(place: 'Canada' , name:'Canada').present?
Place.create!(place: 'Poland' , name:'Poland') unless Place.where(place: 'Poland' , name:'Poland').present?
Place.create!(place: 'Macao ' , name:'Macao') unless Place.where(place: 'Macao ' , name:'Macao').present?
Place.create!(place: 'Netherlands' , name:'Netherlands') unless Place.where(place: 'Netherlands' , name:'Netherlands').present?
Place.create!(place: 'Singapore' , name:'Singapore') unless Place.where(place: 'Singapore' , name:'Singapore').present?
Place.create!(place: 'Hungary' , name:'Hungary') unless Place.where(place: 'Hungary' , name:'Hungary').present?
Place.create!(place: 'Croatia' , name:'Croatia') unless Place.where(place: 'Croatia' , name:'Croatia').present?
Place.create!(place: 'Korea, Rep.' , name:'Korea, Rep.') unless Place.where(place: 'Korea, Rep.' , name:'Korea, Rep.').present?
Place.create!(place: 'Egypt, Arab Rep.' , name:'Egypt, Arab Rep.') unless Place.where(place: 'Egypt, Arab Rep.' , name:'Egypt, Arab Rep.').present?
Place.create!(place: 'Morocco' , name:'Morocco') unless Place.where(place: 'Morocco' , name:'Morocco').present?
Place.create!(place: 'Czech Republic' , name:'Czech Republic') unless Place.where(place: 'Czech Republic' , name:'Czech Republic').present?
Place.create!(place: 'Switzerland' , name:'Switzerland') unless Place.where(place: 'Switzerland' , name:'Switzerland').present?
Place.create!(place: 'South Africa' , name:'South Africa') unless Place.where(place: 'South Africa' , name:'South Africa').present?
Place.create!(place: 'Indonesia' , name:'Indonesia') unless Place.where(place: 'Indonesia' , name:'Indonesia').present?
Place.create!(place: 'Ireland' , name:'Ireland') unless Place.where(place: 'Ireland' , name:'Ireland').present?
Place.create!(place: 'Romania' , name:'Romania') unless Place.where(place: 'Romania' , name:'Romania').present?
Place.create!(place: 'Belgium' , name:'Belgium') unless Place.where(place: 'Belgium' , name:'Belgium').present?
Place.create!(place: 'Denmark' , name:'Denmark') unless Place.where(place: 'Denmark' , name:'Denmark').present?
答案 0 :(得分:4)
您正在使用Solr,您需要启动它:
bundle exec sunspot-solr start -p 8982
和附注,你可以替换这一行:
Topic.create!(topic: 'Scuba Diving') unless Topic.where(topic: 'Scuba Diving').present?
Place.create!(place: 'Belgium' , name:'Belgium') unless Place.where(place: 'Belgium' , name:'Belgium').present?
使用:
Topic.find_or_create_by!(topic: 'Scuba Diving')
Place.find_or_create_by!(place: 'Belgium' , name:'Belgium')
您可以阅读更多here