2013-10-06 4 views
0

не Попытку загрузить файл, используя замедленную работуЗадержка работы возвращается без ошибок метода []

def import 
    @report = current_user.reports.create!(name: params[:report_name]) 
    @contact = @report.contacts.delay.import(params[:file], params[:info_type]) 
    flash[:success]= "Contacts importing, check back in 2-3 minutes" 
    redirect_to contacts_url 
end 

возвращается:

undefined method `import' for [] 

Когда я пытаюсь без ассоциации:

def import 
    @report = current_user.reports.create!(name: params[:report_name]) 
    Contact.delay.import(params[:file], params[:info_type], @report.id) 
    flash[:success]= "Contacts importing, check back in 2-3 minutes" 
    redirect_to contacts_url 
end 

I получить:

undefined method `name' for nil:NilClass 

Импорт:

def self.import(file, info, report_id) 
    CSV.foreach(file.path) do |row| 
     input = row*"" 
     # input = hashy["input"] 
     case info 
     when "email" 
      begin 
       contact_hash = FullContact.person(email: input) 
       if contact_hash.status = 200 
        Contact.create!(input: input, contact_hash: contact_hash.to_json, info_type: info, found: true, pending: false, report_id: report_id) 
       elsif contact_hash.status = 202 
        Contact.create!(input: input, contact_hash: contact_hash.to_json , info_type: info, found: true, pending: true, report_id: report_id) 
       end 
      rescue FullContact::NotFound 
       Contact.create!(input: input, contact_hash: nil, info_type: info, found: false, report_id: report_id) 
      rescue FullContact::Invalid 
      end 
     when "telephone" 
      begin 
      Contact.create!(input: input, contact_hash: FullContact.person(phone: input).to_json, info_type: info, report_id: report) 
      rescue FullContact::NotFound 
       Contact.create!(input: input, contact_hash: "Not Found", info_type: info, report_id: report) 
      rescue FullContact::Invalid 
      end 
     end 
    end 
end 

Я также не то, что я использую gmaps4rails драгоценный камень, который по умолчанию столбцы широта, долгота и GMaps в ноль, пока контакт не будет сохранен в базе данных. Вот почему?

+0

Где этот 'импорт' определен? Вы уверены, что сообщение об ошибке происходит из-за метода 'import'? Как выглядит метод отложенной работы 'import'? – lurker

+0

всегда отправляйте столбец ваших ошибок. из того, что вы пишете, я думаю, что вы должны перечитать документацию delayed_job. он обычно использует метод '.delay' на экземпляре модели типа' @ user.delay.something'. поэтому 'something' будет методом класса' User', и этот класс настроен для работы с DJ – phoet

+0

@phoet, где я могу найти столбец ошибок? –

ответ

0

Использование self.import. Он будет работать, а не только import

def self.import 

end 
+0

Разве я этого не делаю? или вы говорите, вызывая .delay.self.import? –

+0

Я получаю эту ошибку: undefined метод 'import 'для" dcc36a923c445d1ddb6970ec ": String –

+0

Извините, оказывается, я получал ошибку выше, потому что у меня был и Sidekiq gem. Я избавился от этого, теперь получаю: undefined method 'name 'для nil: NilClass –

Смежные вопросы