Skip to content

Commit

Permalink
Safe nav operator to render announcement description on index page
Browse files Browse the repository at this point in the history
Prior to introducing the presence validation on Announcement.description, several announcements were created in production without a description. This broke nil description references and this approach returns nil as a fallback and facilitates type casting
  • Loading branch information
samudary committed Mar 16, 2021
1 parent d17e84f commit 3b5d0ac
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/views/announcements/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<li class="box">
<p class="title is-5"><%= announcement.name %></p>
<p>
<%= announcement.description.truncate(100) %>
<%= link_to("More [*]", announcement_path(announcement)) if announcement.description.length > 100 %>
<%= announcement.description&.truncate(100) %>
<%= link_to("More [*]", announcement_path(announcement)) if announcement.description&.length.to_i > 100 %>
</p>
<% if policy(announcement).change? %>
<footer class="level is-mobile mt-1">
Expand Down

0 comments on commit 3b5d0ac

Please sign in to comment.