Reputation: 1131
I have a field that may be blank, so I need to use Object.try, but I'm having trouble with the syntax when adding the date format.
<%= @request.assigned_date.strftime("%m/%d/%y") %>
How would I change the above to include the ".try" ?
Thanks in advance. Katie
Upvotes: 3
Views: 379
Reputation: 709
I would try:
<%= @request.assigned_date.try(:strftime, "%m/%d/%y") %>
Tell me if that worked for you.
Upvotes: 2
Reputation: 21884
I'd say...
<%= @request.assigned_date.try(:strftime, "%m/%d/%y") %>
Note that it wouldn't work if your field was an empty string. It has to be nil.
Upvotes: 3