Question

It seems Heroku/PostgreSQL doesn't support strftime. So, if I want to convert something like:

@event.date_start.strftime("%B #{@event.date_start.day.ordinalize}")

What are the options without using strftime?


Edit:

Here's my Heroku error log. It's stumbling on strftime, which was working fine in SQLite in my dev environment:

2013-05-19T15:51:07.001968+00:00 app[web.1]: ActionView::Template::Error (undefined method `strftime' for nil:NilClass):
Was it helpful?

Solution

The problem is that @event doesn't have a date_start:

2013-05-19T15:51:07.001968+00:00 app[web.1]: ActionView::Template::Error (undefined method `strftime' for nil:NilClass)

The above error means that strftime is being called on a nil object, which in your case is @event's date_start.

If your event records should always have a date_start then update or delete the problematic one.
Otherwise you can use try:

@event.date_start.try(:strftime, "%B #{@event.date_start.day.ordinalize}")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top