2017-07-17 52 views
1

這裏的show.html.arb文件:ActiveAdmin刪除關聯時無非是想渲染顯示頁面

attributes_table_for resource do 
    row :id 
    row :state 
    row :request_type 
    row :assignee 
    row :assigner 
    row :unassigned 
    row :deleter 
end 

attributes_table_for resource.request do 
    row :id 
end 

而這裏的ActiveAdmin.register請求部分:

show do |resource| 
    render 'show' 
end 

下面是是鏈接用於呈現此頁:

<%= content_tag(:li, link_to('View', accounting_request_path(accnt_request))) %> 

我的問題則是,爲什麼在地球上這告訴我這是試圖刪除 該協會??

這是一個GET請求,而不是PUT或POST請求。

這裏是確切的錯誤:

Failed to remove the existing associated request. The record failed to save when after its foreign key was set to nil. 

這的確是,除去關聯的時候,我只是瀏覽網頁顯示該記錄。 The @2nd column is the association's id

+0

請粘貼show動作的整個日誌。 – JCorcuera

+0

發現問題......感謝提醒我查看日誌,而不僅僅是錯誤消息。呸!我會分享問題所在。 –

回答

0

這個問題沒有顯示這個 - 但其中一個模型作爲after_initialize回調在其中聲明。

日誌告訴我,這方法在這裏被稱爲地方說:build_requestable

app/models/concerns/requestable.rb:6:in `build_requestable' 
app/views/accounting_requests/_show.html.arb:6:in `block in _app_views_accounting_requests__show_html_arb___512970926778810589_70108054037800' 
app/views/accounting_requests/_show.html.arb:1:in `new' 
app/views/accounting_requests/_show.html.arb:1:in `_app_views_accounting_requests__show_html_arb___512970926778810589_70108054037800' 
app/ui/stewgle/tasks/accounting_requests.rb:33:in `block (2 levels) in <top (required)>' 
lib/monkies/aa_views_pages_base.rb:62:in `block in build_page_content' 
lib/monkies/aa_views_pages_base.rb:60:in `build_page_content' 
app/controllers/application_controller.rb:57:in `set_time_zone' 

現在,這裏是什麼文件說,這個回調:

Lastly an after_find and after_initialize callback is triggered for each object that is found and instantiated by a finder, with after_initialize being triggered after new objects are instantiated as well.

這意味着,僅僅通過做ar_object_thingy.associated_thingy它調用after_initialize回調。在這個回調中,我正在做​​(示例)在多態關係中創建一個對象。這實際上正在破壞當前與導致錯誤的未保持對象存在的關係。

TLDR;

在這種情況下,問題不在ActiveRecord中。它與我使用的稱爲after initialize的模型回調調用了打破belongs_to關係的方法。此模型驗證每次通過父級查找父記錄的子級時的存在。