Вопрос

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):
Это было полезно?

Решение

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}")
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top