From 861a2d2d91fccb0931df2d71e8a1fa6c48fd2630 Mon Sep 17 00:00:00 2001 From: Serge L Date: Sun, 29 Mar 2026 11:30:12 -0400 Subject: [PATCH] Fix NoMethodError on nil entryable in account activity feed (#1316) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix NoMethodError when entry has nil entryable Guard against orphaned entries where the entryable record has been deleted but the entry still exists, preventing a crash on the account show page. Co-Authored-By: Claude Opus 4.6 * Add dependent: :destroy to Entryable has_one :entry The polymorphic has_one :entry association lacked a dependent option, meaning if a Transaction/Trade/Valuation was ever deleted directly (bypassing the Entry), the Entry would be left orphaned with a nil entryable — causing NoMethodError in the activity feed. Co-Authored-By: Claude Opus 4.6 * Add nil entryable guard to _split_group.html.erb Same defensive check as _entry.html.erb for consistency. Co-Authored-By: Claude Opus 4.6 --------- Co-authored-by: Claude Opus 4.6 --- app/models/entryable.rb | 2 +- app/views/entries/_entry.html.erb | 6 ++++-- app/views/entries/_split_group.html.erb | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/models/entryable.rb b/app/models/entryable.rb index cf4d22821..d7507fe1b 100644 --- a/app/models/entryable.rb +++ b/app/models/entryable.rb @@ -10,7 +10,7 @@ module Entryable included do include Enrichable - has_one :entry, as: :entryable, touch: true + has_one :entry, as: :entryable, touch: true, dependent: :destroy scope :with_entry, -> { joins(:entry) } diff --git a/app/views/entries/_entry.html.erb b/app/views/entries/_entry.html.erb index 4bdf42aed..3c3f83fa3 100644 --- a/app/views/entries/_entry.html.erb +++ b/app/views/entries/_entry.html.erb @@ -1,4 +1,6 @@ <%# locals: (entry:, balance_trend: nil, view_ctx: "global") %> -<%= render partial: entry.entryable.to_partial_path, - locals: { entry: entry, balance_trend: balance_trend, view_ctx: view_ctx } %> +<% if entry.entryable.present? %> + <%= render partial: entry.entryable.to_partial_path, + locals: { entry: entry, balance_trend: balance_trend, view_ctx: view_ctx } %> +<% end %> diff --git a/app/views/entries/_split_group.html.erb b/app/views/entries/_split_group.html.erb index cf182f8be..978f3d019 100644 --- a/app/views/entries/_split_group.html.erb +++ b/app/views/entries/_split_group.html.erb @@ -2,7 +2,9 @@
<%= render "transactions/split_parent_row", entry: split_group.parent %> <% split_group.children.each do |child_entry| %> - <%= render partial: child_entry.entryable.to_partial_path, - locals: { entry: child_entry, in_split_group: true } %> + <% if child_entry.entryable.present? %> + <%= render partial: child_entry.entryable.to_partial_path, + locals: { entry: child_entry, in_split_group: true } %> + <% end %> <% end %>