Reputation: 6367
I am have a instance variable ride
that comes from a table and it has a column ride.pickup_at
If I do <%= ride.pickup_at.class.name %>
I get
time
So Strftime should be available.
Now, if I do <%= ride.pickup_at.strftime('%x') %>
I get an error
undefined method `strftime' for nil:NilClass
What do I have to do to make strftime available?
Upvotes: 0
Views: 334
Reputation: 300
You can add a if condition like this before your code like this. <%if !ride.pickup_at.nil? %> <%= ride.pickup_at.strftime('%x') %> <% end %> This might be because of some record having nil value for pickup_at
Upvotes: 0
Reputation: 449
you can use try
to do the nil
judge: <%= ride.pickup_at.try(:strftime, '%x') %>
.Or I think you should figure out what to do if ride.pickup_at
is nil
Upvotes: 1