Simplify object and association checks

* check for <object> instead of <object>.nil?
* check for <association>_id? instead of <association>.nil? (avoids
  record loading)
This commit is contained in:
2025-01-16 20:42:18 +01:00
parent c908063212
commit 7962cdf169
13 changed files with 24 additions and 26 deletions

View File

@@ -3,5 +3,5 @@
<% @ancestors.map do |ancestor| %>
<%= turbo_stream.replace ancestor %>
<% end %>
<%= @before.nil? ? turbo_stream.append(:quantities, @quantity) :
turbo_stream.before(@before, @quantity) %>
<%= @before ? turbo_stream.before(@before, @quantity) :
turbo_stream.append(:quantities, @quantity) %>

View File

@@ -8,11 +8,11 @@
<%= turbo_stream.append :quantity_form do %>
<%- tabular_form_with model: @quantity, html: {id: ids[:form_tag]} do |form| %>
<%= form.hidden_field :parent_id unless @quantity.parent.nil? %>
<%= form.hidden_field :parent_id if @quantity.parent_id? %>
<% end %>
<% end %>
<% if @quantity.parent %>
<% if @quantity.parent_id? %>
<%= turbo_stream.remove ids[:row] %>
<%= turbo_stream.after @quantity.parent, partial: 'form', locals: ids %>
<% else %>

View File

@@ -5,5 +5,5 @@
<%= turbo_stream.replace ancestor %>
<% end %>
<% @self_and_progenies.each do |q| %>
<%= @before.nil? ? turbo_stream.append(:quantities, q) : turbo_stream.before(@before, q) %>
<%= @before ? turbo_stream.before(@before, q) : turbo_stream.append(:quantities, q) %>
<% end %>