Hello RoR + Mongo(Mongoid)应用程序在这里
什么是即时错误消息?
Faraday::ConnectionFailed: connection refused: localhost:9200
这是什么时候发生的?当我尝试在控制台中保存用户实例时
User.create!(email:"kevin@gmail.com",password:"helloWorld123",password_confirmation:"helloWorld123")
我将不胜感激任何帮助或意见。祝你度过愉快的一天。谢谢阅读。以下是相关代码的详细信息
1)Gemfile
source 'https://rubygems.org'
group :development, :test do
gem 'rspec-rails', '~> 3.1.0'
gem 'factory_girl_rails', '~> 4.4.1'
gem 'spring', '~> 1.2.0'
end
group :test do
gem 'faker', '~> 1.4.3'
gem 'capybara', '~> 2.4.3'
gem 'database_cleaner', '~> 1.3.0'
gem 'launchy', '~> 2.4.2'
gem 'selenium-webdriver', '~> 2.43.0'
end
gem 'geocoder', '~> 1.2.7'
gem 'figaro', '1.0'
#for cloud uploads (amazon)
gem 'fog', '~> 1.27.0'
#gem 'will_paginate', '~> 3.0.6'
gem "will_paginate_mongoid", '~> 2.0.1'
#for search
gem 'searchkick', '~> 0.8.5'
# managing events
gem 'sidekiq', '3.3.0'
gem 'sinatra', '~> 1.4.5', require: false
gem 'slim', '~> 3.0.1'
# frontend package management
#source 'https://rails-assets.org' do
# gem 'rails-assets-bs-typeahead'
#end
gem 'mechanize', '~> 2.7.3'
# user/privelege stuff
gem 'devise', '~> 3.4.1'
#gem 'therubyracer' V8 javascript interpreter
gem 'omniauth', '~> 1.2.2'
gem 'omniauth-facebook', '~> 2.0.0'
gem 'omniauth-linkedin', '~> 0.2.0'
gem 'pundit', '~> 0.3.0'
# DB options
gem "redis", "~> 3.0.1"
gem 'mongoid', '~> 4', github: 'mongoid/mongoid'
gem 'mongoid_userstamp', '~> 0.4.0'
gem 'bson_ext', '~> 1.5.1'
gem 'moped', '~> 2.0.3'
# display stuff
gem 'haml', '~> 4.0.5'
gem 'rename', '~> 1.0.2'
gem 'bootstrap-sass'
gem 'twitter-bootstrap-rails'
gem 'react-rails', '~> 1.0.0.pre', github: 'reactjs/react-rails'
gem 'magnific-popup-rails', '~> 0.9.9.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails', '~> 3.1.2'
gem 'jquery-ui-rails', '~> 5.0.3'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
#gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
gem 'debugger2', :git => "git://github.com/ko1/debugger2.git"
gem 'browserify-rails'
用户模型
class User
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Userstamp::User
include Connectable, SearchesASCAP, SearchesBMI
#callbacks
after_create :populate_data
after_create :ensure_profile
#relationships
has_and_belongs_to_many :songs, dependent: :nullify
has_and_belongs_to_many :searches, dependent: :destroy
has_one :profile
has_one :writer
has_many :author_conversations, class_name: 'Conversation', inverse_of: :author, dependent: :destroy
has_many :recipient_conversations, class_name: 'Conversation', inverse_of: :recipient, dependent: :destroy
has_many :messages, dependent: :destroy
#validations
validates_presence_of :email, :encrypted_password
#SEARCH
searchkick word_start: [:firstname, :lastname, :display_name, :role, :genre],
locations: ["location"]
def search_data
attributes.merge(
firstname: firstname,
lastname: lastname,
society_id: society_id,
display_name: profile.try(:display_name),
role: profile.try(:role),
city: profile.try(:city),
state: profile.try(:state_code),
genre: profile.try(:genre),
daw: profile.try(:daw),
location: profile.try(:coordinates)
)
end
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable, :omniauth_providers => [:facebook]
## Database authenticatable
field :firstname, type: String, default: ""
field :lastname, type: String, default: ""
field :email, type: String, default: ""
field :encrypted_password, type: String, default: ""
## Recoverable
field :reset_password_token, type: String
field :reset_password_sent_at, type: Time
## Rememberable
field :remember_created_at, type: Time
## Trackable
field :sign_in_count, type: Integer, default: 0
field :current_sign_in_at, type: Time
field :last_sign_in_at, type: Time
field :current_sign_in_ip, type: String
field :last_sign_in_ip, type: String
field :signed_up_on, type: Date, default: Date.today
# Songwriter information
field :society_id, type: String, default: ""
field :ipi_id, type: String, default: ""
field :society, type: String, default: "ASCAP"
# for OmniAuth
field :provider, type: String, default: ""
field :uid, type: String, default: ""
field :timezone, type: String, default: ""
field :access_token, type: String, default: ""
field :expires_at, type: String, default: ""
## Confirmable
# field :confirmation_token, type: String
# field :confirmed_at, type: Time
# field :confirmation_sent_at, type: Time
# field :unconfirmed_email, type: String # Only if using reconfirmable
## Lockable
# field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
# field :unlock_token, type: String # Only if unlock strategy is :email or :both
# field :locked_at, type: Time
default_scope -> {order_by(:firstname.asc, :lastname.asc)}
# OMNIAUTH
def self.new_with_session(params, session)
super.tap do |user|
if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
user.email = data["email"] if user.email.blank?
user.firstname = data["firstname"] if user.firstname.blank?
user.lastname = data["lastname"] if user.lastname.blank?
end
end
end
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.password = Devise.friendly_token[0,20]
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.firstname = auth.info.first_name
user.lastname = auth.info.last_name
user.timezone = auth.extra.raw_info.timezone
user.access_token = auth.credentials.access_token
user.expires_at = auth.credentials.expires_at
Profile.create(
user: user,
image: auth.info.image,
display_name: user.firstname + " " + user.lastname
)
end
end
def full_name
self.firstname + " " + self.lastname
end
def location
if self.profile.state_code
self.profile.city + ", " + self.profile.state_code
else
self.profile.city
end
end
## SCRAPING
def populate_data
DiscographyWorker.perform_async(self.id.to_s)
end
def ensure_profile
if self.profile.nil?
self.profile = Profile.new
end
end
def scrape_discography
# validate user has entered ascap_id or ipi_id
if self.society == 'ASCAP'
populate_ascap
elsif self.society == 'BMI'
populate_bmi
end
end
end
完整错误跟踪
Faraday::ConnectionFailed: connection refused: localhost:9200
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:641:in `rescue in connection_for'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:589:in `connection_for'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:994:in `request'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.1/lib/faraday/adapter/net_http_persistent.rb:26:in `perform_request'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.1/lib/faraday/adapter/net_http.rb:40:in `block in call'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.1/lib/faraday/adapter/net_http_persistent.rb:22:in `with_net_http_connection'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.1/lib/faraday/adapter/net_http.rb:32:in `call'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.1/lib/faraday/rack_builder.rb:139:in `build_response'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.1/lib/faraday/connection.rb:377:in `run_request'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/elasticsearch-transport-1.0.7/lib/elasticsearch/transport/transport/http/faraday.rb:21:in `block in perform_request'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/elasticsearch-transport-1.0.7/lib/elasticsearch/transport/transport/base.rb:187:in `call'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/elasticsearch-transport-1.0.7/lib/elasticsearch/transport/transport/base.rb:187:in `perform_request'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/elasticsearch-transport-1.0.7/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/elasticsearch-transport-1.0.7/lib/elasticsearch/transport/client.rb:115:in `perform_request'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/elasticsearch-api-1.0.7/lib/elasticsearch/api/actions/index.rb:99:in `index'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/searchkick-0.8.7/lib/searchkick/index.rb:44:in `store'
... 20 levels...
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/railties-4.1.7/lib/rails/commands/console.rb:9:in `start'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:69:in `console'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/railties-4.1.7/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
from /Users/apprentice/Documents/work/fourleafapp/bin/rails:8:in `<top (required)>'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:241:in `load'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:241:in `block in load'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/apprentice/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:241:in `load'
from /Users/apprentice/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/apprentice/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
答案 0 :(得分:2)
请确保您的Elasticsearch正在运行
答案 1 :(得分:0)
每当创建用户时,都会更新elasticsearch中的索引 这是一个弹性搜索错误,没有正确配置端口