gpt4 book ai didi

ruby-on-rails - Elasticsearch、轮胎与协会

转载 作者:数据小太阳 更新时间:2023-10-29 06:55:00 26 4
gpt4 key购买 nike

运行:Ruby 1.9.3p0(2011-10-30 修订版 33570)[x86_64-darwin11.2.0],Rails 3.2.0

我正在尝试通过跨协会的 TIRE gem 进行 Elasticsearch 。出于某种原因,在 TIRE 导入或偶尔在 View 上执行 rake 时,我不断收到以下错误/错误:

Daves-MacBook-Pro:outdoor dave$ rake environment tire:import CLASS=Gear FORCE=true
[IMPORT] Deleting index 'gears'
[IMPORT] Creating index 'gears' with mapping:
{"gear":{"properties":{}}}
[IMPORT] Starting import for the 'Gear' class
--------------------------------------------------------------------------------
101/101 | 100% rake aborted!######################################
undefined method `last_name' for nil:NilClass

Tasks: TOP => tire:import

这是我的模型:齿轮

class Gear < ActiveRecord::Base
attr_accessible :title, :size, :price, :image_url, :sub_category_id, :user_id
belongs_to :user
belongs_to :sub_category

validates :title, presence: true
validates :size, presence: true
validates :price, presence: true
validates :sub_category_id, presence: true
validates :user_id, presence: true

include Tire::Model::Search
include Tire::Model::Callbacks


def self.search(params)
tire.search(load: true, page: params[:page], per_page: 18) do
query { string params[:query]} if params[:query].present?
end
end

def to_indexed_json
to_json(methods: [:sub_category_name, :user_last_name, :user_first_name, :user_email])
end

def sub_category_name
sub_category.name
end

def user_first_name
user.first_name
end

def user_last_name
user.last_name
end

def user_email
user.email
end
end

用户

class User < ActiveRecord::Base
attr_accessible :first_name, :last_name, :email, :password, :password_confirmation
has_secure_password
has_many :gears
before_save :create_remember_token

email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

validates :first_name, presence: true,
length: {:maximum => 50 }
validates :last_name, presence: true,
length: {:maximum => 50 }
validates :email, presence: true,
format: {:with => email_regex},
uniqueness: {:case_sensitive => false}
validates :password, presence: true,
confirmation: true,
length: {within: 6..40}

def name
first_name + " " + last_name
end

private

def create_remember_token
self.remember_token = SecureRandom.urlsafe_base64
end
end

子类别

class SubCategory < ActiveRecord::Base
attr_accessible :name
belongs_to :category
has_many :gears
end

我错过了什么?谢谢。

最佳答案

我的数据库中有一些 NIL 值,这是错误的原因。希望这可以为一些人节省一些时间。

关于ruby-on-rails - Elasticsearch、轮胎与协会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9671827/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com