NoMethodError: undefined `getlocal 'method for a DateTime object

When a user logs in to my site, Devise tries to update the field in the current_sign_in_at user model over time. But he produces this error:

 NoMethodError: undefined method `getlocal' for Mon, 08 Nov 2010 03:11:01 +0000:DateTime [GEM_ROOT]/gems/activesupport-3.0.1/lib/active_support/time_with_zone.rb:75 

I found several resources where people mentioned this problem. There is a problem on Github without an answer. This page has a solution that works in my development environment because it involves editing /lib/active_support/time_with_zone.rb , but I need a solution that will also work in my production environment on Heroku. Is there a way to use my edited version of /lib/active_support/time_with_zone.rb on Heroku? Or is there a better way to deal with this problem?

Here is what I use:

 Rails 3.0.1 ruby 1.9.2p0 (2010-08-18 revision 29036) 

Thank you for reading.

+3
source share
2 answers
  irb> Time.now.getlocal => Mon Nov 08 15:04:05 +0200 2010 

but

 irb>DateTime.now.getlocal NoMethodError: undefined method `getlocal' for Mon, 08 Nov 2010 15:05:16 +0200:DateTime from (irb):17 

So, I suppose you need to convert the DateTime object to Time

Update

You can use the Ruby mixin technique, something like

 irb > module DateTimePatch irb ?> def get_local irb ?> "works!" irb ?> end irb ?> end => nil irb > DateTime.send(:include, DateTimePatch) => DateTime irb2 > DateTime.now.get_local => "works!" 
+2
source

I know this question was 2 years ago, but I think I found a clearer explanation of why it behaves in this way, found in this question. Just for those who probably need additional explanations like me.

+2
source

All Articles