Rails 3 Object.try syntax
I have a field that can be empty, so I need to use Object.try, but when I add the date format, I am having syntax problems.
<%= @request.assigned_date.strftime("%m/%d/%y") %>
How can I change the above to include ".try"?
Thanks in advance. Katie
+3
Katie M
source
to share
2 answers
I would say ...
<%= @request.assigned_date.try(:strftime, "%m/%d/%y") %>
Note that this will not work if your field was an empty string. It should be zero.
+3
Robin
source
to share
I would try:
<%= @request.assigned_date.try(:strftime, "%m/%d/%y") %>
Tell me if it worked for you.
+2
flooooo
source
to share