[英]Resque can't update objects - rails
我試圖做一個簡單的導入后台作業,以使用resque導入一些csv信息。
作業運行了,但是一旦我編輯了一個對象,它似乎就毀了或什么了……
運行此作業后,它將找到具有第一行的用戶...然后,在@ user.name上將其未設置,然后將其保存。 我可以在控制台中運行此代碼,並且效果很好,僅在resque中損壞。 是否存在不能使用對象或無法通過resque寫入數據庫的限制? 到目前為止,浪費了6個小時嘗試各種事物……請幫助。
def self.perform(chunk)
chunk.each do |i|
@user = User.where(:email => i[:email].to_s).first_or_initialize
@user.name = i[:name].to_s
if @user.save
puts @user.email
entity = Entity.find_by_email_domain(@user.email)
eur = EntityUser.where(:entity_id => entity.id, :user_id => @user.id).first_or_initialize
if eur.save
puts "Start: BLARGITY End"
topic = Topic.where(:number => i[:course_number].to_s).first_or_initialize
eu = TopicUser.where(:topic_id => topic.id, :user_id => user.id, :role_i => 1).first_or_initialize
else
eu = TopicUser.where(:topic_id => topic.id, :user_id => user.id).first_or_initialize
end
eu.save
end
end
end
end
我只是嘗試做這樣的查找,現在您可以看到錯誤了。
NoMethodError:未定義的方法'name ='為nil:NilClass
@user = User.find_by_email(i[:email])
puts "sdfdsf"
@user.name = i[:name]
puts @user.name
我正在使用smarter_csv發送“塊”,這是一個哈希。 我猜想當redis序列化哈希時,您需要先對它進行符號化,然后才能再次使用它。
chunk.each do |i|
i.symbolize_keys!
@user = User.find_by_email(i[:email])
@user.name = i[:name]
象征它的作品!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.