2017-07-17 6 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

質問にはこれが表示されませんが、モデルの1つにafter_initializeというコールバックが含まれています。

ログは、それがbuild_requestable言うところこの方法は、ここで呼び出されていることを教えてください:

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.

これはちょうどによって意味:今

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' 

、ここではドキュメントはこのコールバックについて言っているのですar_object_thingy.associated_thingyを実行すると、after_initializeコールバックが呼び出されます。そのコールバック内で、私は​​(例)を実行して、多態性の関係内でオブジェクトを作成します。これは実際にはエラーを引き起こしている非永続オブジェクトとの現在の関係を破壊しています。

TLDR;

この場合、ActiveRecordでは問題が発生しません。私が使用しているモデルコールバックであるafter initializeは、belongs_to関係を破るメソッドを呼び出しています。このモデルは、親レコードの子を親から検索するたびにその存在を検証します。

関連する問題