2012-03-12 12 views
8

Esecuzione: Rubino 1.9.3p0 (2011-10-30 revisione 33570) [x86_64-darwin11.2.0], Rails 3.2.0elasticsearch, Tire & Associazioni

Sto cercando di ottenere elasticsearch lavoro attraverso la Gemma di TIRE attraverso le associazioni. Per qualche motivo continuo a ricevere il seguente errore/errori durante l'esecuzione di un rastrello su un'importazione del pneumatico o di tanto in tanto su una visione:

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 

Qui sono i miei modelli: GEAR

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 

UTENTE

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+\-.][email protected][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 

Sub_Category

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

Che cosa mi manca? Grazie.

+2

Aggiornamento: Ok si è verificato che avevo alcuni valori NIL nel mio database che erano il motivo degli errori. Spero che questo possa salvare alcune persone un po 'di tempo. – DaveG

+1

Ciao, bene è risolto - quindi il processo di importazione è morto quando un autore era 'nil'? ... Inoltre, potresti riutilizzarlo: https://github.com/karmi/railscasts-episodes/commit/ee1f6f39002f32ad25134c81dd6de74ff1b708fa per indicizzare le associazioni senza creare i metodi speciali ... – karmi

+0

Sì, il processo di importazione non avrebbe funzionato perché alcune delle mie associazioni chiavi esterne erano nulle. Non sembrava che piacesse. Grazie per il suggerimento, darò un'occhiata a questo. – DaveG

risposta

2

Ho avuto alcuni valori NIL nel mio database che è stato il motivo degli errori. Spero che questo possa salvare alcune persone un po 'di tempo.