Undefined method “getlocal” when displaying created_at?

老子叫甜甜 提交于 2019-12-07 07:58:46

问题


i use rails 3.2.6, ruby 1.9.3 with the mongoid gem 3.0.

i want to display the created_at field of a database entry, but get the following error:

undefined method `getlocal' for "Wed, 25 Apr 2012 15:04:37 -0400":String

here's the rails code:

<dt>Erstellt am:</dt><dd><%= @app.created_at %></dd>

any advice what's the problem? is there a bugfix? should work in my opinion?

thanks in advance!


回答1:


try adding the following to your model

include Mongoid::Timestamps

see http://mongoid.org/en/mongoid/docs/extras.html#timestamps




回答2:


getlocal is a method on the Time class, so it may be a problem of intermixing object types. The system is expecting the @app.created_at to be an instance of Time, not DateTime. Make sure the field type for created_at is DateTime and that when creating/updating this field, make sure the object you put in is also a DateTime object.




回答3:


if you use mongoid, instead of
@app.created_at
try
@app[:created_at]
this worked for me



来源:https://stackoverflow.com/questions/11242935/undefined-method-getlocal-when-displaying-created-at

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!