首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >延迟的作业不返回任何方法错误[]

延迟的作业不返回任何方法错误[]
EN

Stack Overflow用户
提问于 2013-10-06 11:36:31
回答 1查看 284关注 0票数 0

正在尝试使用延迟作业上载文件

代码语言:javascript
复制
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

返回:

代码语言:javascript
复制
undefined method `import' for []

当我尝试不使用关联时:

代码语言:javascript
复制
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

我得到了:

代码语言:javascript
复制
undefined method `name' for nil:NilClass

导入:

代码语言:javascript
复制
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

我也不应该说我使用的是gmaps,它默认将纬度、经度和gmaps4rails列设置为nil,直到联系人被保存到数据库中。这就是原因吗?

EN

回答 1

Stack Overflow用户

发布于 2013-10-07 01:32:58

使用self.import。它将会工作,而不仅仅是import

代码语言:javascript
复制
def self.import

end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19205152

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档