Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird uninitialized constant error (Rails)

The following code

class Schedule < ActiveRecord::Base     
  def self.get  
     today = TZInfo::Timezone.get('America/New_York').utc_to_local(Time.now.utc).to_date
  end    
end

produces the following error:

uninitialized constant Schedule::TZInfo

but only when I'm not running it from script/console. Thoughts?

(Also, is there a better way to get the current date in a given time zone?)

like image 379
Tom Lehman Avatar asked Mar 19 '26 01:03

Tom Lehman


1 Answers

Have you tried adding

require 'tzinfo'
like image 92
Reuben Mallaby Avatar answered Mar 22 '26 04:03

Reuben Mallaby