Re: [mongoid] Can't print created_at timestamp. undefined method `getlocal'...

473 views
Skip to first unread message

Durran Jordan

unread,
Jul 11, 2012, 4:48:32 AM7/11/12
to mon...@googlegroups.com
Can I see the model and view code please?

2012/7/11 Tronic <clemens...@gmail.com>
hi.

i think this is an mongoid issue. when i add mongoid timestamps to my model and want to print the created_at timestamp in one of my views, i get the following error:

undefined method `getlocal' for "Wed, 11 Jul 2012 02:39:24 -0400":String
any advice on this?

thanks!



Tronic

unread,
Jul 11, 2012, 5:05:03 AM7/11/12
to mon...@googlegroups.com
model:

class App
  include Mongoid::Document
  include Mongoid::Timestamps

  field :name, :type => String
  field :bundle, :type => String
  field :license, :type => String
  field :auth_count, :type => Integer
  field :type, :type => Integer, :default => 0
  field :active, :type => Boolean, :default => true
  
  validates_uniqueness_of :name, :case_sensitive => false
  
  belongs_to :user
  has_one :order
end


view code:

<%= @app.created_at %>

Luca G. Soave

unread,
Jul 16, 2012, 4:56:47 PM7/16/12
to mon...@googlegroups.com

It happen to me too during an update flow Rails 3.2.3 --> 3.2.6 / Mongoid 3.0.1 ...
here it is another similar case on stackoverflow

Luca G. Soave

unread,
Jul 16, 2012, 6:08:12 PM7/16/12
to mon...@googlegroups.com

I guess something goes wrong with a mixin somewere :

lsoave@ubuntu:~/rails/github/gitwatcher$ rails c
Loading development environment (Rails 3.2.6)
1.9.3-p194 :001 > Time.now.getlocal
 => 2012-07-17 00:00:15 +0200
1.9.3-p194 :002 > DateTime.now.getlocal
NoMethodError: undefined method `getlocal' for Tue, 17 Jul 2012 00:02:45 +0200:DateTime
    from (irb):2
    from /home/lsoave/.rvm/gems/ruby-1....@rails-3.2.6/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
    from /home/lsoave/.rvm/gems/ruby-1....@rails-3.2.6/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
    from /home/lsoave/.rvm/gems/ruby-1....@rails-3.2.6/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
1.9.3-p194 :003 >

my offending string is in 28 line @ app/views/shared/_watch-list-table.html.haml which is :

28:           %td= repo.created_at.to_s(:pretty)

and it used working before ...

Durran Jordan

unread,
Jul 17, 2012, 2:33:06 AM7/17/12
to mon...@googlegroups.com
Yeah I'm still looking into this - created_at should be a Time, not a DateTime, and is defined as such in Mongoid's module.

2012/7/17 Luca G. Soave <luca....@gmail.com>

Luca G. Soave

unread,
Jul 21, 2012, 10:36:11 AM7/21/12
to mon...@googlegroups.com


It's not a mongoid/moped issue, there were a data corruption, probably caused by switching between branches with different mongoid - mongo/moped versions, with the mongodb opened and connected ...

I just dropped the database and mongorestore a backup, to solve the problem.


On Tuesday, July 17, 2012 8:33:06 AM UTC+2, Durran Jordan wrote:
Yeah I'm still looking into this - created_at should be a Time, not a DateTime, and is defined as such in Mongoid's module.

2012/7/17 Luca G. Soave <luca....@gmail.com>

I guess something goes wrong with a mixin somewere :

lsoave@ubuntu:~/rails/github/gitwatcher$ rails c
Loading development environment (Rails 3.2.6)
1.9.3-p194 :001 > Time.now.getlocal
 => 2012-07-17 00:00:15 +0200
1.9.3-p194 :002 > DateTime.now.getlocal
NoMethodError: undefined method `getlocal' for Tue, 17 Jul 2012 00:02:45 +0200:DateTime
    from (irb):2
    from /home/lsoave/.rvm/gems/ruby-1.9.3-...@rails-3.2.6/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
    from /home/lsoave/.rvm/gems/ruby-1.9.3-...@rails-3.2.6/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
    from /home/lsoave/.rvm/gems/ruby-1.9.3-...@rails-3.2.6/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
Reply all
Reply to author
Forward
0 new messages