我試過同樣的情景在rails console
未定義的方法`每個」對Rails 3.2
但爲什麼我收到...
未定義的方法each
,我有一個回調,將更新的形式立即
after_update :check_app_on_update?
def check_app_on_update?
self.each do |ppmp|
ppmp_year = ppmp.year
get_app = AnnualProcurementPlan.where(year: ppmp_year)
get_id = get_app.map{|a| a.id }
get_id.each do |app_id|
update_attribute(:annual_procurement_plan_id, app_id)
end
end
end
但繼續得到undefined method 'each'
但每當我刪除self.each
環......
我得到'stack level too deep'
類型的錯誤。
任何解決方法將不勝感激。
編輯
好了,現在我意識到,我應該堅持我的老辦法。那就是沒有each
def check_app_on_update?
ppmp_year = self.year
get_app = AnnualProcurementPlan.where(year: ppmp_year)
get_id = get_app.map{|a| a.id }
get_id.each do |app_id|
# ppmp = ProjectProcurementManagementPlan.last
# ppmp.update_attribute(:annual_procurement_plan_id, app_id)
@idd = app_id
end
update_attribute(:annual_procurement_plan_id, @idd)
end
但我正在逐漸stack level too deep
錯誤
我從日誌中看到,有是一個無限循環。
(0.5ms) UPDATE "project_procurement_management_plans" SET "status" = 'Approved', "updated_at" = '2013-05-31 09:55:00.000000', "annual_procurement_plan_id" = 1 WHERE "project_procurement_management_plans"."id" = 19
AnnualProcurementPlan Load (0.5ms) SELECT "annual_procurement_plans".* FROM "annual_procurement_plans" WHERE "annual_procurement_plans"."year" = 2012
(0.2ms) ROLLBACK
Completed 500 Internal Server Error in 16737ms
SystemStackError - stack level too deep:
(gem) actionpack-3.2.11/lib/action_dispatch/middleware/reloader.rb:70:in `'
你想要什麼檢查確切嗎?剛剛更新的對象?或其他記錄? – MrYoshiji
正在更新的對象 – xirukitepe
因此,您想要遍歷其屬性?或者只是一個特定的? – MrYoshiji