Undefined method “getlocal” when displaying create

2019-05-09 08:51发布

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!

3条回答
霸刀☆藐视天下
2楼-- · 2019-05-09 09:15

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.

查看更多
Rolldiameter
3楼-- · 2019-05-09 09:25

try adding the following to your model

include Mongoid::Timestamps

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

查看更多
疯言疯语
4楼-- · 2019-05-09 09:34

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

查看更多
登录 后发表回答