문제

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