Skip to content

Commit

Permalink
Merge pull request #960 from bullet-train-co/jeremy/empty-attributes
Browse files Browse the repository at this point in the history
Better handling for empty values in some attributes
  • Loading branch information
jagthedrummer authored Nov 21, 2024
2 parents 779fdd9 + bb36c8e commit 036d606
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<% object ||= current_attributes_object %>
<% strategy ||= current_attributes_strategy || :none %>
<% url ||= nil %>
<% default_message = local_assigns[:default_message] || t("global.not_set") %>
<% display_when_blank = local_assigns[:display_when_blank] || false %>
<%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
<% unless object[attribute].nil? %>
<%= t("#{object.class.name.underscore.pluralize}.fields.#{attribute}.options.#{object.public_send(attribute)}") %>
<% if !object[attribute].nil? || display_when_blank %>
<%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
<% unless object[attribute].nil? %>
<%= t("#{object.class.name.underscore.pluralize}.fields.#{attribute}.options.#{object.public_send(attribute)}") %>
<% else %>
<%= default_message %>
<% end %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
<% strategy ||= current_attributes_strategy || :none %>
<% url ||= nil %>
<% default_message = local_assigns[:default_message] || t('global.formats.timestamp_unavailable') %>
<% display_when_blank = local_assigns[:display_when_blank] || false %>
<% if object.public_send(attribute).present? %>
<% if object.public_send(attribute).present? || display_when_blank %>
<%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
<%= display_date(object.public_send(attribute), **local_assigns.slice(:format), **local_assigns.slice(:date_format)) %>
<% if object.public_send(attribute).present? %>
<%= display_date(object.public_send(attribute), **local_assigns.slice(:format), **local_assigns.slice(:date_format)) %>
<% else %>
<%= default_message %>
<% end %>
<% end %>
<% else %>
<%= default_message %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
<% strategy ||= current_attributes_strategy || :none %>
<% url ||= nil %>
<% default_message = local_assigns[:default_message] || t('global.formats.timestamp_unavailable') %>
<% display_when_blank = local_assigns[:display_when_blank] || false %>
<% if object.public_send(attribute).present? %>
<% if object.public_send(attribute).present? || display_when_blank %>
<%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
<%= display_date_and_time(object.public_send(attribute), **local_assigns.slice(:format), **local_assigns.slice(:date_format), **local_assigns.slice(:time_format)) %>
<% if object.public_send(attribute).present? %>
<%= display_date_and_time(object.public_send(attribute), **local_assigns.slice(:format), **local_assigns.slice(:date_format), **local_assigns.slice(:time_format)) %>
<% else %>
<%= default_message %>
<% end %>
<% end %>
<% else %>
<%= default_message %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
<% strategy ||= current_attributes_strategy || :none %>
<% url ||= nil %>
<% default_message = local_assigns[:default_message] || t("global.never") %>
<% display_when_blank = local_assigns[:display_when_blank] || false %>
<%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
<% if object.public_send(attribute) %>
<%= t("global.time_ago", time: time_ago_in_words(object.send(attribute))) %>
<% else %>
<%= default_message %>
<% if object.public_send(attribute) || display_when_blank %>
<%= render 'shared/attributes/attribute', object: object, attribute: attribute, strategy: strategy, url: url do %>
<% if object.public_send(attribute).present? %>
<%= t("global.time_ago", time: time_ago_in_words(object.send(attribute))) %>
<% else %>
<%= default_message %>
<% end %>
<% end %>
<% end %>
1 change: 1 addition & 0 deletions bullet_train/config/locales/en/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ en:
creator: Bullet Train, Inc.
time_ago: "%{time} ago"
never: Never
not_set: Not Set
buttons:
other: Other
debug: Debug
Expand Down

0 comments on commit 036d606

Please sign in to comment.